Compare commits
53
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7f587b5e36 | ||
|
|
ee0559a52f | ||
|
|
aef92c1d58 | ||
|
|
b5f8c9ff32 | ||
|
|
a7d96f208f | ||
|
|
eeec748d41 | ||
|
|
08308f2588 | ||
|
|
14909a3504 | ||
|
|
6a3484e1a3 | ||
|
|
0400dc56b4 | ||
|
|
8a8165eeea | ||
|
|
02336e6a0a | ||
|
|
d4d259cd23 | ||
|
|
175ed5c4e2 | ||
|
|
dc83f97be4 | ||
|
|
7f7d7588f3 | ||
|
|
b9c6d193a4 | ||
|
|
062adaf9d3 | ||
|
|
1cf4074eb3 | ||
|
|
bc6f087efb | ||
|
|
8cb1756d6c | ||
|
|
851811eb35 | ||
|
|
f5802cf34a | ||
|
|
c9bb6efa43 | ||
|
|
67fcd7923e | ||
|
|
26568429bc | ||
|
|
f3720ff2c1 | ||
|
|
68716b9e56 | ||
|
|
c2d850a0d0 | ||
|
|
6d62ca5677 | ||
|
|
58aac77a0b | ||
|
|
0462ab1f88 | ||
|
|
60fca4d540 | ||
|
|
dba5d49448 | ||
|
|
1633c7bb7b | ||
|
|
7eda6c50a4 | ||
|
|
f2ae2a7de7 | ||
|
|
3210b3bd15 | ||
|
|
9fad051f75 | ||
|
|
a818822023 | ||
|
|
012184af30 | ||
|
|
c1f7ffb5b4 | ||
|
|
6816081644 | ||
|
|
433004598d | ||
|
|
02d8355a83 | ||
|
|
89010b2425 | ||
|
|
0ff1d23e4a | ||
|
|
fd29865e7a | ||
|
|
42564b537f | ||
|
|
598e00171c | ||
|
|
b849bb2b4d | ||
|
|
fc7dd02ee2 | ||
|
|
caf1638fdc |
No files matched your search
@@ -0,0 +1,223 @@
|
||||
---
|
||||
name: garbage-collector
|
||||
description: Daily maintenance agent that reads pre-scanned gc-findings.json, then opens Tier A draft PRs (mechanical fixes like removing stale TODOs and console.logs) and Tier B GitHub Issues (architectural drift, oversized files, outdated deps). Runs headless via the garbage-collector.yml cron. Also invokable interactively as @garbage-collector for manual sweeps.
|
||||
tools: Read, Grep, Glob, Bash, Edit, Write
|
||||
model: haiku
|
||||
color: orange
|
||||
---
|
||||
|
||||
You are the WorldWideView Garbage Collector — a low-cost maintenance agent responsible for keeping the codebase clean between human-led development cycles.
|
||||
|
||||
## Step 1 — Read your charter
|
||||
|
||||
```bash
|
||||
cat .agents/rules/garbage-collection.md
|
||||
```
|
||||
|
||||
Internalize all guard rails, caps, and the never-touch list before taking any action.
|
||||
|
||||
## Step 2 — Read the findings
|
||||
|
||||
```bash
|
||||
cat gc-findings.json
|
||||
```
|
||||
|
||||
This was produced by `scripts/gc-scan.mjs` before you were invoked. You do **not** re-scan the codebase — you triage this list only.
|
||||
|
||||
If `gc-findings.json` does not exist or is empty, output "No findings to process." and stop.
|
||||
|
||||
## Step 3 — Check dry-run mode
|
||||
|
||||
```bash
|
||||
echo "${DRY_RUN:-false}"
|
||||
```
|
||||
|
||||
If `true`, jump to **Step 7 (Dry-run summary)** and skip all PR/Issue creation.
|
||||
|
||||
## Step 4 — Check for existing GC work (idempotency)
|
||||
|
||||
```bash
|
||||
# Open gc-bot PRs
|
||||
gh pr list --label gc-bot --state open --json number,title,headRefName,body
|
||||
|
||||
# Existing gc/* remote branches
|
||||
git branch -r --list 'origin/gc/*'
|
||||
|
||||
# Open gc-bot Issues
|
||||
gh issue list --label gc-bot --state open --json number,title
|
||||
```
|
||||
|
||||
Build a mental map of already-handled concerns. For each finding, skip it if an open PR or Issue already covers the same file + pattern.
|
||||
|
||||
## Step 5 — Tier A: Create draft PRs (max 3 per run)
|
||||
|
||||
Group related Tier A findings by `patternId` or `type`. Process the highest-value group first (most findings → most cleanup per PR).
|
||||
|
||||
For each group (up to 3 total):
|
||||
|
||||
### 5a — Create a branch
|
||||
|
||||
```bash
|
||||
SHA=$(git rev-parse --short HEAD)
|
||||
BRANCH="gc/<patternId>-${SHA}"
|
||||
git checkout -b "${BRANCH}"
|
||||
```
|
||||
|
||||
### 5b — Apply the mechanical fix
|
||||
|
||||
Follow these per-type rules:
|
||||
|
||||
**stale-todo (issueClosed: true)**
|
||||
Delete the entire comment line. Do not change surrounding code.
|
||||
|
||||
**stale-todo (issueClosed: false, age > 90d)**
|
||||
Add `# STALE(gc-bot):` prefix to the comment so the human sees it needs resolution. Do not delete — the human decides. This makes it Tier A-lite (no code risk, just marks it).
|
||||
|
||||
**anti-pattern: mdc-ref**
|
||||
Replace `.mdc` with `.md` in the file content. Check that the referenced file actually exists with `.md` extension before renaming.
|
||||
|
||||
**anti-pattern: console-log**
|
||||
Delete the `console.log(...)` line entirely. If it's the only statement in a block, delete the block too (only if the block has no other statements).
|
||||
|
||||
**anti-pattern: ts-ignore**
|
||||
Delete the `// @ts-ignore` line. If the next line now has a type error that is trivially fixable (e.g., adding a missing cast), fix it. If the type error is non-trivial, revert to Tier B (create an Issue instead).
|
||||
|
||||
**anti-pattern: ts-nocheck**
|
||||
Delete the `// @ts-nocheck` line. Check if the file still compiles cleanly with `npx tsc --noEmit --skipLibCheck` — if not, revert the deletion and file a Tier B Issue instead.
|
||||
|
||||
### 5c — Verify the change is safe
|
||||
|
||||
```bash
|
||||
# Count changed lines — must be ≤150
|
||||
git diff --stat
|
||||
|
||||
# Quick type check on changed files only
|
||||
npx tsc --noEmit --skipLibCheck 2>&1 | head -20
|
||||
```
|
||||
|
||||
If changed lines exceed 150 or type errors are introduced, `git checkout .` and file a Tier B Issue for this group instead.
|
||||
|
||||
### 5d — Commit and push
|
||||
|
||||
```bash
|
||||
git add -p # stage only the GC changes
|
||||
git commit -m "chore: [gc] remove <N> stale <type> findings"
|
||||
git push origin "${BRANCH}"
|
||||
```
|
||||
|
||||
### 5e — Open a draft PR
|
||||
|
||||
```bash
|
||||
gh pr create --draft --label gc-bot \
|
||||
--title "chore: [gc] <short description (≤60 chars)>" \
|
||||
--body "$(cat <<'EOF'
|
||||
## What changed
|
||||
<bullet list of files and what was removed/changed>
|
||||
|
||||
## Why
|
||||
Detector: `<patternId>` in `scripts/gc-scan.mjs`
|
||||
Rule violated: `<rule from garbage-collection.md>`
|
||||
Age / evidence: <age in days, or closed issue number>
|
||||
|
||||
## How to verify
|
||||
1. <step>
|
||||
2. Run `pnpm test` — all tests should still pass
|
||||
3. Run `pnpm build` — build must be clean
|
||||
|
||||
> This PR was opened automatically by the GC bot. Review before merging.
|
||||
EOF
|
||||
)"
|
||||
```
|
||||
|
||||
Return to main: `git checkout main`
|
||||
|
||||
## Step 6 — Tier B: Create GitHub Issues (max 5 per run)
|
||||
|
||||
Group related Tier B findings into one Issue per `type` (e.g., all oversized files in one Issue).
|
||||
|
||||
```bash
|
||||
gh issue create --label gc-bot \
|
||||
--title "[gc] <type>: <short description>" \
|
||||
--body "$(cat <<'EOF'
|
||||
## Summary
|
||||
<what was detected and why it matters>
|
||||
|
||||
## Files / packages affected
|
||||
<file list with line counts or versions>
|
||||
|
||||
## Suggested action
|
||||
<concrete next step — e.g., "split this file", "upgrade this dep", "fix this rule reference">
|
||||
|
||||
## How to close this
|
||||
Resolve the issue and close this ticket manually.
|
||||
|
||||
> Filed automatically by the GC bot on <date>.
|
||||
EOF
|
||||
)"
|
||||
```
|
||||
|
||||
## Step 7 — Dry-run summary
|
||||
|
||||
Find or create the tracking Issue:
|
||||
|
||||
```bash
|
||||
gh issue list --label gc-bot --state open --search "[gc-bot] Daily Scan Reports" --json number,title
|
||||
```
|
||||
|
||||
If it does not exist:
|
||||
```bash
|
||||
gh issue create --label gc-bot \
|
||||
--title "[gc-bot] Daily Scan Reports" \
|
||||
--body "This issue collects daily dry-run scan summaries. Enable normal mode by setting DRY_RUN=false in the workflow."
|
||||
```
|
||||
|
||||
Then post a comment:
|
||||
```bash
|
||||
gh issue comment <number> --body "$(cat <<'EOF'
|
||||
## GC Dry-run Report — <date>
|
||||
|
||||
| Tier | Count | Types |
|
||||
|---|---|---|
|
||||
| A (would fix) | <n> | <comma-separated types> |
|
||||
| B (would file) | <n> | <comma-separated types> |
|
||||
|
||||
### Tier A findings
|
||||
<table: file | line | type | description>
|
||||
|
||||
### Tier B findings
|
||||
<table: file/package | type | description>
|
||||
|
||||
No PRs or Issues were created (dry-run mode).
|
||||
EOF
|
||||
)"
|
||||
```
|
||||
|
||||
## Step 8 — Output summary
|
||||
|
||||
Print a clean markdown summary:
|
||||
|
||||
```
|
||||
## GC Run Complete
|
||||
|
||||
### PRs opened (<n>/3)
|
||||
- #<number>: <title> (<branch>)
|
||||
|
||||
### Issues opened (<n>/5)
|
||||
- #<number>: <title>
|
||||
|
||||
### Skipped (already handled)
|
||||
- <n> findings skipped — covered by existing open work
|
||||
|
||||
### Not actioned
|
||||
- <n> Tier B findings below cap — will appear in next run
|
||||
```
|
||||
|
||||
If nothing was created: "No new findings requiring action."
|
||||
|
||||
## Important invariants
|
||||
|
||||
- Never touch the never-touch list in the charter.
|
||||
- Never create a PR with more than 150 changed lines.
|
||||
- Never mark a PR as ready-for-review.
|
||||
- Never push directly to `main`.
|
||||
- If a Tier A fix risks introducing a regression and you cannot verify it is safe, file a Tier B Issue instead — safety always beats throughput.
|
||||
@@ -0,0 +1,52 @@
|
||||
#!/usr/bin/env bash
|
||||
# Syncs .planning git branch to match the active worldwideview branch.
|
||||
# Called by: Claude Code SessionStart hook, git post-checkout hook.
|
||||
# Convention: .planning branch name == worldwideview branch name.
|
||||
# Falls back to main if no matching .planning branch exists.
|
||||
|
||||
PLANNING_DIR="C:/dev/wwv/.planning"
|
||||
|
||||
# Exit silently if .planning repo doesn't exist on this machine
|
||||
if [ ! -d "$PLANNING_DIR/.git" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD 2>/dev/null)
|
||||
|
||||
# Exit if not in a git repo or in detached HEAD state
|
||||
if [ -z "$CURRENT_BRANCH" ] || [ "$CURRENT_BRANCH" = "HEAD" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Only sync if CWD is worldwideview or a worktree of it
|
||||
GIT_COMMON=$(git rev-parse --git-common-dir 2>/dev/null)
|
||||
if ! echo "$GIT_COMMON" | grep -qi "worldwideview"; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Skip if .planning is already on the right branch
|
||||
PLANNING_CURRENT=$(git -C "$PLANNING_DIR" rev-parse --abbrev-ref HEAD 2>/dev/null)
|
||||
if [ "$PLANNING_CURRENT" = "$CURRENT_BRANCH" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Skip if .planning has uncommitted changes (don't clobber in-progress work)
|
||||
if ! git -C "$PLANNING_DIR" diff --quiet 2>/dev/null || ! git -C "$PLANNING_DIR" diff --cached --quiet 2>/dev/null; then
|
||||
echo "{\"continue\":true,\"suppressOutput\":false,\"message\":\"[planning-sync] Skipping: .planning has uncommitted changes\"}"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Switch to matching branch, or fall back to main
|
||||
if git -C "$PLANNING_DIR" branch --list "$CURRENT_BRANCH" | grep -q .; then
|
||||
if git -C "$PLANNING_DIR" checkout "$CURRENT_BRANCH" --quiet 2>/dev/null; then
|
||||
echo "{\"continue\":true,\"suppressOutput\":false,\"message\":\"[planning-sync] .planning -> $CURRENT_BRANCH\"}"
|
||||
else
|
||||
echo "{\"continue\":true,\"suppressOutput\":false,\"message\":\"[planning-sync] WARNING: checkout of '$CURRENT_BRANCH' failed\"}"
|
||||
fi
|
||||
else
|
||||
if git -C "$PLANNING_DIR" checkout main --quiet 2>/dev/null; then
|
||||
echo "{\"continue\":true,\"suppressOutput\":false,\"message\":\"[planning-sync] No branch '$CURRENT_BRANCH' in .planning; staying on main\"}"
|
||||
else
|
||||
echo "{\"continue\":true,\"suppressOutput\":false,\"message\":\"[planning-sync] WARNING: fallback checkout to main failed\"}"
|
||||
fi
|
||||
fi
|
||||
@@ -1,169 +0,0 @@
|
||||
---
|
||||
trigger: model_decision
|
||||
description: Architecture rules and conventions for the WorldwideView Next.js 16 frontend application, state management, and CesiumJS integration.
|
||||
---
|
||||
|
||||
# WorldwideView Application Architecture
|
||||
|
||||
## 1. Core Framework
|
||||
- Built on **Next.js 16 (App Router)** with `output: "standalone"`.
|
||||
- Uses **React 19** and **TypeScript 5** (strict mode).
|
||||
- **Styling**: Strictly Vanilla CSS. No Tailwind or CSS-in-JS.
|
||||
- **Component File Size**: Max 150 lines per file. Split components, extract helpers, and use hooks for anything larger.
|
||||
|
||||
## 2. State & Event Bus
|
||||
- **Zustand**: Slices handle global state (`globe`, `layers`, `timeline`, `ui`, `filter`, `data`, `config`, `favorites`, `geojson`).
|
||||
- **DataBus**: Custom typed pub/sub singleton (`DataBus.getInstance().emit()`) decoupling React components from background WebSocket streams.
|
||||
|
||||
## 3. Edition System
|
||||
Features are controlled by `NEXT_PUBLIC_WWV_EDITION`:
|
||||
- `local`: Self-hosted, full features, auth.
|
||||
- `cloud`: Managed instance.
|
||||
- `demo`: Public demo, no auth.
|
||||
|
||||
## Source Layout
|
||||
|
||||
|
||||
```
|
||||
worldwideview/
|
||||
├── .agents/ # AI agent workflows, rules, memories, skills
|
||||
├── docs/ # Public-facing documentation
|
||||
├── artifacts/
|
||||
│ └── context/ # ← THIS FOLDER — private source of truth (not committed)
|
||||
├── packages/ # Plugin packages (workspaces)
|
||||
├── public/ # Static assets (Cesium assets, GeoJSON data files)
|
||||
├── scripts/ # Build/utility scripts (copy-cesium.mjs, scaffold-osm-plugin.mjs, etc.)
|
||||
└── src/
|
||||
├── app/ # Next.js App Router (layouts, pages, API routes)
|
||||
├── components/ # React UI components (HUD, LayersPanel, Panels, Sidebar)
|
||||
├── core/
|
||||
│ ├── data/ # DataBus, PollingManager, CacheLayer
|
||||
│ ├── globe/ # Cesium hooks, viewer lifecycle, primitive collections
|
||||
│ └── plugins/ # Plugin registry, lifecycle, loaders
|
||||
├── lib/ # Shared utilities, server-side logic
|
||||
│ └── marketplace/ # Marketplace bridge (auth, token, CORS, repository)
|
||||
└── plugins/ # Built-in feature plugins (aviation, maritime, borders, etc.)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Module Breakdown
|
||||
|
||||
### `src/core/data/` — The Heartbeat
|
||||
|
||||
- **DataBus**: Decentralized event pipeline for all system actions. Plugins emit, components subscribe.
|
||||
- **PollingManager**: Intelligent scheduler for external API calls with exponential backoff.
|
||||
- **CacheLayer**: 2-stage persistent caching — In-Memory + IndexedDB (`worldwideview-cache`).
|
||||
|
||||
### `src/core/globe/` — Rendering Engine
|
||||
|
||||
- **Cesium Integration**: Low-level control over the Cesium Viewer and Primitive Collections.
|
||||
- **EntityRenderer**: High-performance Primitive-based renderer. See `Primitives vs. Entities` below.
|
||||
- **Spiderifier & Clustering Engine** (`StackManager.ts` & `stackAnimation.ts`):
|
||||
- Automatically identifies overlapping entities and groups them into geometrically balanced clusters (concentric rings for <18 density, Fermat's golden spiral for massive stacks).
|
||||
- **Mobile Layout Constraints**: Integrates responsive coordinate geometry. Modifies logical icon dimensions via `iconUpscaler.ts` (32px mobile / 48px desktop) and scales the radial expansion offsets proportionally by 70% on mobile displays to ensure tight, aesthetically pleasing clusters without massive gaps.
|
||||
- **Z-Fighting Mitigation**: Clustering involves highly frequent stack rebuild cycles on any zoom/pan delta. To prevent chaotic render flickering, the global `AnimationLoop` explicitly yields visibility management to `stackAnimation.ts` via `isEntityClustered()`. Items transitioning into the `collapsed` state intentionally bypass animation lerping (to prevent 220ms ghost visibility bleed) and mathematically cloak themselves instantly.
|
||||
- Globe is initialized via `GlobeView.tsx`. Viewer instance passed via `CesiumContext`.
|
||||
|
||||
### `src/core/plugins/` — Plugin System
|
||||
|
||||
- **PluginManager**: Registers, boots, and destroys plugins. Enforces capability checks.
|
||||
- **Loaders**: Plugins are dynamically imported at runtime as ES module bundles (`loadPluginFromManifest`). The legacy `StaticDataPlugin` and `DeclarativePlugin` runtimes are fully deprecated.
|
||||
- **Manifest Requirement**: All plugins MUST include a `"worldwideview"` manifest block in their `package.json` (containing `id`, `icon`, `category`, and `format`). This is strictly required by the Marketplace in order to parse display attributes correctly.
|
||||
|
||||
---
|
||||
|
||||
## Performance: Primitives vs. Entities
|
||||
|
||||
**Core design decision:** Use Cesium `Primitive` API instead of the high-level `Entity` API for high-count datasets.
|
||||
|
||||
| Feature | Entity API | Primitive API (WWV) |
|
||||
|---|---|---|
|
||||
| **Abstraction** | High (easy to use) | Low (direct GPU access) |
|
||||
| **JS Overhead** | Significant per-entity objects | Minimal (batched draw calls) |
|
||||
| **Max Capacity** | ~1,000 entities | **100,000+ points/billboards** |
|
||||
| **WWV Use Case** | Info window / detail panel content | Live data point visualization |
|
||||
|
||||
Specifically: `PointPrimitiveCollection` and `BillboardCollection` ensure 60FPS even with dense global data. The full migration from Entity-based rendering to Primitives was completed to eliminate severe FPS drops.
|
||||
|
||||
---
|
||||
|
||||
## Globe Occlusion & Depth Testing
|
||||
|
||||
- **Correct approach:** `depthTestAgainstTerrain = false` — uses GPU to depth-test against the smooth WGS84 ellipsoid. Icons visible on the near hemisphere, correctly occluded behind Earth.
|
||||
- **Avoid:** `eyeOffset`, `disableDepthTestDistance` hacks that push entities in front of everything. These cause icons to bleed through the globe.
|
||||
- The Plugin SDK's `CesiumEntityOptions` exposes this via `disableDepthTestDistance` when absolutely needed for specific usecases.
|
||||
|
||||
---
|
||||
|
||||
## Data Pipeline (Example: Aviation)
|
||||
|
||||
```
|
||||
Remote API (e.g. OpenSky)
|
||||
↓ [raw JSON, every ~30s via PollingManager]
|
||||
Plugin (e.g. AviationPlugin)
|
||||
↓ [parse, filter, sanitize → GeoEntity[]]
|
||||
DataBus.emit("dataUpdated", { entities })
|
||||
↓
|
||||
EntityRenderer [batched Primitive update]
|
||||
↓
|
||||
GPU (CesiumJS) → 60FPS visualization
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Database (Unified PostgreSQL)
|
||||
|
||||
**Location:** We have migrated from a fragmented SQLite + PostgreSQL setup to a unified **PostgreSQL** architecture using Prisma 7 with the `@prisma/adapter-pg` driver. This enables true multi-tenant cloud capability, real-time sync, and scalable connection pooling via `DATABASE_URL`.
|
||||
|
||||
**Next.js Core Tables:**
|
||||
| Model | Table | Purpose |
|
||||
|---|---|---|
|
||||
| `User` | `users` | Auth accounts (email, bcrypt password, role) |
|
||||
| `InstalledPlugin` | `installed_plugins` | Marketplace plugin install records |
|
||||
| `Setting` | `settings` | Key-value app config (Cesium token, map style, etc.) |
|
||||
| `Tenant` | `tenants` | Multi-tenant organization boundaries |
|
||||
|
||||
**Data Engine Tables:**
|
||||
Managed explicitly via optimized queries in `packages/wwv-data-engine/src/db.ts` targeting PostgreSQL to maximize ingest performance.
|
||||
Includes tables like `iranwar_events`, `earthquakes`, `wildfires`, and `maritime_history`.
|
||||
|
||||
> [!WARNING]
|
||||
> **Catastrophic Time-Series Polling (The Lookback Trap):**
|
||||
> High-frequency polling (e.g. 6,000 aircraft every 10s) accumulates millions of rows rapidly.
|
||||
> - **DO NOT** query unindexed columns (like `ts`) for lookback/freshness without a dedicated index, otherwise you will trigger full table scans and 500 Route timeout errors.
|
||||
> - **REQUIRED:** Implement aggressive data retention / hourly pruning via `scheduler.ts` to prevent infinite table growth.
|
||||
> - **PREFERRED:** Keep real-time / spatial lookbacks in Redis (like `getLiveSnapshot()`), and leave PostgreSQL strictly for historical chronological replays that hit standard indices.
|
||||
|
||||
**Hot-Caching (Redis) & Connection Rules:**
|
||||
The `wwv-data-engine` polls external APIs, dumps raw payloads to PostgreSQL for historical persistence, and broadcasts active snapshots via WebSockets while persisting to Upstash Redis. The Next.js frontend fetches initial state from Redis to ensure horizontal scalability.
|
||||
*TLS Connection Requirement:* The `REDIS_URL` mapped in Coolify and `.env.local` must use the `rediss://` protocol for TLS encryption. Attempting to use plain `redis://` with Upstash will cause the connection to drop (`ECONNRESET`) and throw a `MaxRetriesPerRequestError (which is 3)` inside the data engine.
|
||||
*Upstash Request Limit Throttling:* Due to Upstash Serverless billing (capped at 10k requests/day or 500k/month on free tier), the data engine decouples WebSocket live broadcasting from Redis persistence. High-frequency scrapers (like Aviation) run every 15 seconds to push WebSockets, but the backend forces a **5-minute throttle** before saving the next snapshot to Upstash using `zlib` compression. This executes just 2 commands (`SET` and `EXPIRE`) per 5 minutes per scraper, completely eliminating `max requests limit exceeded` errors while retaining real-time frontend updates.
|
||||
|
||||
**Resilience (Data Self-Healing):**
|
||||
Even with persistent PostgreSQL, critical history (like `iranwarlive` events) should be bundled as `seed.json` or `history.csv` artifacts. If the Data Engine detects an empty table, it MUST parse its built-in fallback seed to hydrate the database and Redis, ensuring 100% data recovery without manual intervention.
|
||||
|
||||
**Dynamic Engine URL Resolution:**
|
||||
The decoupled Data Engine lives at `http://localhost:5001` during local development, and deploys to `https://dataengine.worldwideview.dev` in production. The Next.js frontend injects this context directly into the plugin via the `ctx.env` object (specifically reading from `NEXT_PUBLIC_WWV_PLUGIN_DATA_ENGINE_URL` environment variables). Plugins resolve their required backend natively by parsing `this.context.env.DATA_ENGINE_URL`. The legacy `globalThis.__WWV_ENGINE_URL__` proxy approach has been fully deprecated.
|
||||
|
||||
---
|
||||
|
||||
## Settings Architecture
|
||||
|
||||
User-configurable values live in the `settings` table (not `.env`). They can be updated without rebuilds.
|
||||
|
||||
| Setting Type | Where | Example |
|
||||
|---|---|---|
|
||||
| **Infrastructure** | `.env` | `DATABASE_URL`, `NEXT_PUBLIC_WWV_EDITION` |
|
||||
| **User settings** | `settings` table (DB) | Cesium token, map style, API keys |
|
||||
|
||||
**Setup Wizard:** If `cesium_token` is missing from the DB on first load, the app shows a setup wizard. Plugin-level wizards work the same way — plugin declares required settings in its manifest; if missing, it renders a setup form instead of data.
|
||||
|
||||
---
|
||||
|
||||
## Design Principles
|
||||
|
||||
- **Single Responsibility:** Plugins only handle data mapping — they don't know about UI or cache.
|
||||
- **Dependency Inversion:** `PluginManager` communicates via the `WorldPlugin` interface — new plugins don't require core changes.
|
||||
- **Event-Driven:** Components subscribe to what they need via DataBus — no prop-drilling.
|
||||
- **Defensive Programming:** All external calls wrapped in error boundaries + `PollingManager` backoff.
|
||||
@@ -1,7 +1,9 @@
|
||||
---
|
||||
trigger: glob
|
||||
description: Strict guidelines for rendering geospatial entities, handling 3D terrain clipping, and applying dynamic animation properties against Cesium's runtime engine.
|
||||
globs: "src/core/globe/**/*"
|
||||
paths:
|
||||
- "src/core/globe/**/*"
|
||||
- "src/plugins/**/*"
|
||||
- "packages/wwv-plugin-*/src/**/*"
|
||||
---
|
||||
|
||||
# Cesium Rendering Rules
|
||||
@@ -23,6 +25,23 @@ When creating primitive objects:
|
||||
- **Points** (`PointPrimitive`): Can use `size`, `outlineWidth`, and `outlineColor`.
|
||||
- **Billboards** (`BillboardGraphics` for SVG/Icons): Must **NOT** use `size`, `outlineWidth`, or `outlineColor`. You must use `iconScale` to resize them. Mixing point properties on billboards causes severe shader clipping.
|
||||
|
||||
## Sizing Conventions
|
||||
|
||||
| Entity type | Knob | Default | Typical band | Source |
|
||||
|-------------|--------------|------------------------------------|------------------|--------|
|
||||
| `point` | `size` | `8` desktop / `12` mobile | 5–12 | `src/core/globe/primitiveOps.ts` (`defaultPointSize`) |
|
||||
| `billboard` | `iconScale` | `0.7` (`DEFAULT_BILLBOARD_SCALE`) | 0.6–0.9 | `src/core/globe/primitiveOps.ts` (`DEFAULT_BILLBOARD_SCALE`) |
|
||||
| `model` | `modelScale` | `1.0` + `modelMinPixelSize` | varies per asset | `src/core/globe/ModelManager.ts`, `src/core/globe/hooks/useModelRendering.ts` |
|
||||
|
||||
> [!IMPORTANT]
|
||||
> **Cross-plugin parity rule.** If your plugin renders alongside maritime / aviation / military-aviation on the globe, **leave `iconScale` unset** (or pick a value inside 0.6–0.9). A value below 0.5 will look visibly broken next to peer plugins. A value above 1.0 will dominate the globe.
|
||||
|
||||
> [!CAUTION]
|
||||
> **Silent-ignore footgun.** `size` is a `PointPrimitive` property. If you set `size` on a `billboard` entity it is **silently dropped** — Cesium does not error and the billboard simply renders at `DEFAULT_BILLBOARD_SCALE`. When converting a point plugin to a billboard plugin, replace `size: N` with `iconScale: ~N/16` (the canvas base is `getBaseSize() = 48px` desktop) — do not delete it and do not translate it literally as `iconScale: N/10`. This footgun has shipped at least once (see commit history on `local-plugins/wwv-plugin-satellite`).
|
||||
|
||||
> [!NOTE]
|
||||
> **Backdrop stack.** `createSvgIconUrl` (in the SDK) already wraps the icon in a 44×44 SVG with a dark backdrop circle. `src/core/globe/iconUpscaler.ts` then redraws onto a 48px canvas with **another** backdrop circle (`DEFAULT_BG = "rgba(15, 23, 42, 0.55)"`). Pass `background: false` to `createSvgIconUrl` when you want only the host's circle. Don't add a third backdrop in your own SVG.
|
||||
|
||||
## Performance Culling
|
||||
|
||||
> [!TIP]
|
||||
|
||||
@@ -1,8 +1,16 @@
|
||||
---
|
||||
trigger: model_decision
|
||||
description: Cloud edition implementation details, PostgreSQL Row-Level Security (RLS) isolation, cross-subdomain auth, and cryptographic license keys.
|
||||
paths:
|
||||
- "src/lib/auth*"
|
||||
- "src/app/api/auth/**/*"
|
||||
- "src/core/auth.ts"
|
||||
- "src/core/storage.ts"
|
||||
- "src/core/tenant.ts"
|
||||
---
|
||||
|
||||
> **SUPERSEDED by ADR-003** (`docs/architecture/decisions/adr-0003-shared-identity-and-ecosystem-auth-host.md`).
|
||||
> The auth host is `worldwideview.dev` (worldwideview-web repo), not `app.worldwideview.dev`. Read ADR-003 first.
|
||||
|
||||
# WorldWideView — Cloud & Auth Architecture
|
||||
|
||||
|
||||
@@ -14,25 +22,16 @@ description: Cloud edition implementation details, PostgreSQL Row-Level Security
|
||||
|
||||
## Auth Strategy
|
||||
|
||||
**Auth.js (NextAuth)** is the single auth API across all editions. `app.worldwideview.dev` owns **all auth UI** — login, registration, password reset. No other subdomain ever shows a login or registration form.
|
||||
|
||||
```typescript
|
||||
// src/lib/auth.ts
|
||||
const providers = isCloud
|
||||
? [SupabaseProvider({ /* delegates to Supabase Auth (GoTrue) */ })]
|
||||
: [Credentials({ /* local bcrypt + PostgreSQL */ })];
|
||||
|
||||
export const { auth, signIn, signOut } = NextAuth({ providers });
|
||||
```
|
||||
|
||||
Application code is **identical** across editions — always calls `auth()`, `signIn()`, `signOut()`.
|
||||
|
||||
**One account for the entire ecosystem:**
|
||||
- Cloud instance (`[user].app.worldwideview.dev`)
|
||||
- Marketplace (browse, install, publish) — via SSO redirect
|
||||
- Local instance Bridge API connection
|
||||
|
||||
**Marketplace never owns auth UI** — it redirects to `app.worldwideview.dev/login?redirect_to=marketplace...` for all sign-in.
|
||||
> [!NOTE]
|
||||
> **See [ADR-003](../../docs/architecture/decisions/adr-0003-shared-identity-and-ecosystem-auth-host.md) for the canonical auth architecture.**
|
||||
> The implementation described below (NextAuth as ecosystem IdP, `app.worldwideview.dev` as auth host) was superseded on 2026-05-22. Phase 2A-D (completed 2026-05-25) implemented the ADR-003 architecture:
|
||||
> - **Supabase Auth** is the identity provider for the cloud edition
|
||||
> - **`worldwideview.dev`** owns login, signup, and auth callback routes (`/login`, `/signup`, `/auth/callback`)
|
||||
> - **NextAuth** (Credentials provider) remains active for the local and demo editions only
|
||||
> - Session cookies use `@supabase/ssr` `createServerClient` scoped to `NEXT_PUBLIC_WWV_COOKIE_DOMAIN`
|
||||
> - Both worldwideview and worldwideview-marketplace use the same `buildCookieOptions()` recipe
|
||||
>
|
||||
> The multi-tenant RLS, tier matrix, license key, and CI/CD sections below remain valid.
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
---
|
||||
trigger: always_on
|
||||
---
|
||||
|
||||
# Context and Memory Synchronization
|
||||
|
||||
## 1. Purpose
|
||||
This specification ensures that any agent maintains persistent, accurate project context by pointing them directly to the Single Source of Truth for this repository.
|
||||
|
||||
## 2. Synchronization Target
|
||||
The agent MUST orient itself by immediately reading:
|
||||
1. `c:\dev\worldwideview\AGENTS.md` (The root index of all technical stack details)
|
||||
2. `c:\dev\worldwideview\.agents\rules\platform-architecture.md` (The high-level platform goals)
|
||||
|
||||
If deep technical rules are required for a specific domain (e.g., UI state, Map Rendering, Monorepo management), the agent MUST consult the relevant file in `c:\dev\worldwideview\.agents\rules\`.
|
||||
|
||||
## 3. Reflecting Changes
|
||||
If the architecture fundamentally changes (e.g., migrating off Zustand, or removing Cesium), the agent MUST proactively update the `AGENTS.md` and relevant files in `.agents/rules/` to reflect this new reality.
|
||||
|
||||
## 4. Goal
|
||||
A new chat instance MUST be able to reconstruct an accurate, comprehensive understanding of the project solely from reading the root `AGENTS.md` file and branching out to the specific rules as necessary. This prevents context bloat and ensures accuracy.
|
||||
@@ -1,28 +0,0 @@
|
||||
---
|
||||
trigger: always_on
|
||||
description: Guidelines for ongoing project maintenance, cleanliness, and self-correction during everyday development tasks.
|
||||
---
|
||||
|
||||
# Continuous Improvement & Maintenance
|
||||
|
||||
As an AI agent working within the WorldWideView project, you are expected to practice the **Boy Scout Rule**: always leave the codebase (and its context) cleaner than you found it.
|
||||
|
||||
While executing your primary programming tasks, you MUST actively abide by these maintenance protocols:
|
||||
|
||||
## 1. Documentation & Rule Parity
|
||||
- **Self-Correction**: If you notice that an architectural choice you are implementing contradicts an existing rule in `.agents/rules/`, you must halt and update the rule file to reflect the new paradigm.
|
||||
- **Dead Context**: If you encounter context, plans, or architectural files referencing deprecated concepts (e.g., legacy microservices, `StaticDataPlugin`), proactively prune or update them.
|
||||
|
||||
## 2. Codebase Cleanliness
|
||||
- **Dead Code**: If you refactor a file and leave behind unused functions, imports, or CSS classes, clean them up immediately. Do not leave "commented out" code unless explicitly requested for future use.
|
||||
- **Console Logs**: Remove debugging `console.log` statements before finalizing a feature, except for structured error logging or critical startup info.
|
||||
- **Sandbox Hygiene**: Any throwaway scripts or debugging tools placed in `/local-scripts/` should be deleted once the underlying issue is resolved, unless they provide permanent utility.
|
||||
|
||||
## 3. Dependency & Typings Checks
|
||||
- **Type Safety**: Never use `any` or `@ts-ignore` as a shortcut when refactoring. Always build the proper TypeScript interfaces.
|
||||
- **Manifest Validation**: Whenever you touch a plugin, ensure its `package.json` `"worldwideview"` manifest block is completely accurate and synced with its capabilities.
|
||||
|
||||
## 4. The "See Something, Say Something" Rule
|
||||
If you spot an unrelated but obvious bug, security vulnerability, or architectural anti-pattern in the file you are editing:
|
||||
1. Fix it if it's a minor, isolated issue (and document the fix in your summary).
|
||||
2. For larger issues, explicitly call it out to the user so it can be added to the technical debt backlog.
|
||||
@@ -1,6 +1,9 @@
|
||||
---
|
||||
trigger: model_decision
|
||||
description: Architecture rules and dependency management guidelines for wwv-data-engine seeders.
|
||||
description: Architecture rules and dependency management guidelines for wwv-data-engine seeders, pnpm workspace dependency loading, and WebSocket payload contracts.
|
||||
paths:
|
||||
- "packages/**/*"
|
||||
- "local-seeders/**/*"
|
||||
- "docker-compose.yml"
|
||||
---
|
||||
|
||||
# Data Engine V2 Architecture & Dependency Loading
|
||||
@@ -28,4 +31,61 @@ In production, the `wwv-data-engine-v2` does NOT mount the local file system. In
|
||||
4. It then runs a single **workspace-aware `pnpm install --prod`**. This ensures all custom unbundled dependencies declared by the extracted plugins are downloaded directly into the container and properly linked together.
|
||||
|
||||
## 5. Namespace Separation Rule
|
||||
To prevent collisions and `404` or `ERR_MODULE_NOT_FOUND` errors, seeders **MUST NOT** exist simultaneously in both the community (`wwv-seeders-community`) and private (`wwv-seeders-private`) repositories. Namespace overlaps will cause module resolution failures when the V2 engine attempts to load them. Private seeders have priority.
|
||||
To prevent collisions and `404` or `ERR_MODULE_NOT_FOUND` errors, seeders **MUST NOT** exist simultaneously in both the community (`wwv-seeders`, cloned to `local-seeders/community/`) and private (`wwv-seeders-private`, cloned to `local-seeders/private/`) repositories. Namespace overlaps will cause module resolution failures when the V2 engine attempts to load them. Private seeders have priority.
|
||||
|
||||
## 6. Plugin ID Contract — Single Source of Truth
|
||||
|
||||
> **See ADR-0002** (`docs/architecture/decisions/adr-0002-seeder-exported-name-as-canonical-plugin-id.md`) for full rationale and alternatives considered.
|
||||
|
||||
**Rule:** Every seeder MUST export a `name` field that exactly matches the corresponding frontend plugin's `id` field (kebab-case).
|
||||
|
||||
```typescript
|
||||
// ✅ Correct — seeder src/index.ts
|
||||
export default {
|
||||
name: "gps-jamming", // MUST equal the frontend plugin id
|
||||
cron: "0 0 * * *",
|
||||
fn: seedGpsJam,
|
||||
};
|
||||
|
||||
// ❌ Wrong — do not use folder names, camelCase, or abbreviations
|
||||
export default {
|
||||
name: "gpsjam", // mismatch — frontend plugin is "gps-jamming"
|
||||
...
|
||||
};
|
||||
```
|
||||
|
||||
**How the engine uses it:** `seeder-loader.ts` reads each seeder's exported `name` as the canonical plugin ID. This ID is used for:
|
||||
- The `/manifest` endpoint's `plugins` array (what the frontend checks for local routing)
|
||||
- WebSocket data messages (`pluginId` field)
|
||||
- Redis keys (`data:<name>:live`)
|
||||
- Scheduler logs
|
||||
|
||||
**Folder names are organizational only.** The engine warns at startup if `toKebabCase(folderName) !== seeder.name`, but this is cosmetic — the seeder's exported `name` always wins. Folder renames are a future cleanup, not a functional requirement.
|
||||
|
||||
**Frontend side:** `resolveEngineUrl(pluginId)` checks `localEngineHasPlugin(pluginId)` against the manifest. If the names match, the plugin routes to `ws://localhost:5000/stream`. No alias maps or translation layers are needed.
|
||||
|
||||
## 7. WebSocket Payload Format Contract
|
||||
|
||||
When a seeder calls `setLiveSnapshot(pluginId, payload, ttl)`, the engine broadcasts:
|
||||
```json
|
||||
{ "type": "data", "pluginId": "my-plugin", "payload": <whatever you passed> }
|
||||
```
|
||||
|
||||
**`WsClient` payload handling rules (in order):**
|
||||
|
||||
1. Plugin has `mapWebsocketPayload(payload, existingEntities)` → called with raw payload → must return `GeoEntity[]`
|
||||
2. No handler + payload **is** a flat `GeoEntity[]` array → used directly (timestamp normalized)
|
||||
3. No handler + payload is **any other object** → **silently dropped** with a console warning
|
||||
|
||||
This means:
|
||||
|
||||
| Seeder sends | Frontend needs | Notes |
|
||||
|---|---|---|
|
||||
| `[{id, latitude, longitude, ...}]` | Nothing (WsClient handles) | ✅ Simplest for basic point data |
|
||||
| `{ items: [{...}] }` | `mapWebsocketPayload` | Standard engine snapshot format |
|
||||
| `{ satellites: [{...}] }` | `mapWebsocketPayload` | Named-collection format |
|
||||
|
||||
**Recommendation:** If the seeder and frontend plugin are developed together, use a **flat `GeoEntity[]` array** — no `mapWebsocketPayload` needed. Use named objects (e.g. `{ satellites: [...] }`) only when the seeder data has a domain-specific shape worth preserving; in that case you **must** implement `mapWebsocketPayload` on the frontend plugin.
|
||||
|
||||
> [!CAUTION]
|
||||
> The most common silent bug: seeder sends `{ items: [...] }` (an object), frontend plugin omits `mapWebsocketPayload`. Data arrives but WsClient drops it with a console warning. The globe stays empty. Always implement `mapWebsocketPayload` for any plugin whose seeder sends an object payload.
|
||||
@@ -1,3 +1,9 @@
|
||||
---
|
||||
description: Rules for safe Prisma schema changes, defensive migrations, and PostgreSQL DDL operations.
|
||||
paths:
|
||||
- "prisma/**/*"
|
||||
---
|
||||
|
||||
# Database Migrations & Schema Modification Rules
|
||||
|
||||
## 1. Defensive Migrations
|
||||
@@ -7,10 +13,22 @@ When making database schema changes, you must ensure that generated migrations a
|
||||
- **Add "IF EXISTS" clauses**: Prisma can sometimes produce brittle drop statements (`DROP INDEX "my_index"`). To prevent migrations from crashing if a state desynchronization occurs, manually edit the migration file to use `DROP INDEX IF EXISTS "my_index";` or `DROP TABLE IF EXISTS "table_name";`.
|
||||
- **Data Preservation**: When dropping columns or renaming, carefully review the migration to ensure data is correctly mapped. In PostgreSQL, ensure that cascaded drops don't accidentally remove required data.
|
||||
|
||||
## 2. Managing Failed Migrations
|
||||
## 2. P3005 Auto-Baseline (Handled in `docker-entrypoint.sh`)
|
||||
|
||||
`docker-entrypoint.sh` automatically recovers from Prisma **P3005** ("schema not empty, no migration history"). This happens when `pnpm dev` (which runs `prisma db push`) populates the database before the Docker stack is started.
|
||||
|
||||
The entrypoint only auto-baselines when **both** conditions hold:
|
||||
1. The error is exactly P3005.
|
||||
2. `prisma migrate diff` reports zero schema drift between the live DB and `prisma/schema.prisma`.
|
||||
|
||||
If drift is detected the container exits with a clear error message directing you to `pnpm db:reset`.
|
||||
|
||||
> **Never add manual `migrate resolve --applied` calls** unless you are outside the container and have independently verified the above two conditions. The entrypoint already handles the common case.
|
||||
|
||||
## 3. Managing Failed Migrations
|
||||
If a migration fails in production:
|
||||
- **Never blindly mark as resolved**: Do not run `prisma migrate resolve --applied <migration_name>` unless you have explicitly verified that the database schema precisely matches the expected state.
|
||||
- If you use `resolve --applied`, Prisma will permanently skip that migration in the future, leaving your database structurally out of sync with your Prisma Client.
|
||||
|
||||
## 3. Backups Before DDL
|
||||
## 4. Backups Before DDL
|
||||
Never perform direct DDL operations (ALTER, DROP, CREATE) on a production database without first confirming an automated backup exists, or manually taking a `pg_dump` backup of the database.
|
||||
@@ -1,3 +1,12 @@
|
||||
---
|
||||
description: Docker build patterns, pnpm dev commands, Vitest strategy, Coolify deployment rules, and security headers.
|
||||
paths:
|
||||
- "Dockerfile"
|
||||
- "docker-compose.yml"
|
||||
- ".github/**/*"
|
||||
- "next.config.ts"
|
||||
---
|
||||
|
||||
# Deployment, Testing, and Operations
|
||||
|
||||
## Development Commands
|
||||
|
||||
@@ -1,69 +0,0 @@
|
||||
# Directory Structure & Repositories
|
||||
|
||||
## Directory Structure
|
||||
|
||||
```
|
||||
worldwideview/
|
||||
├── src/
|
||||
│ ├── app/ # Next.js App Router (pages, API routes, layouts)
|
||||
│ │ ├── api/ # Server-side API routes (auth, aviation, camera, etc.)
|
||||
│ │ ├── login/ # Login page
|
||||
│ │ ├── setup/ # First-time setup page
|
||||
│ │ └── globals.css # Root stylesheet
|
||||
│ ├── components/
|
||||
│ │ ├── common/ # Shared UI: BootOverlay, FloatingWindow, PluginIcon
|
||||
│ │ ├── layout/ # AppShell, Header, SearchBar, DataBusSubscriber
|
||||
│ │ ├── panels/ # LayerPanel, EntityInfoCard, FilterPanel, GraphicsSettings
|
||||
│ │ ├── timeline/ # Timeline component
|
||||
│ │ ├── marketplace/ # Plugin install/unverified dialogs
|
||||
│ │ ├── ui/ # Tooltip, ReloadToast
|
||||
│ │ └── video/ # Floating video manager
|
||||
│ ├── core/
|
||||
│ │ ├── data/ # DataBus, PollingManager, CacheLayer, SmartFetcher
|
||||
│ │ ├── filters/ # filterEngine (applies plugin filters to entities)
|
||||
│ │ ├── globe/ # GlobeView, EntityRenderer, AnimationLoop, StackManager,
|
||||
│ │ │ │ CameraController, InteractionHandler, SelectionHandler,
|
||||
│ │ │ │ ModelManager, ImageryProviderFactory
|
||||
│ │ │ └── hooks/ # useCameraActions, useEntityRendering, useModelRendering, etc.
|
||||
│ │ ├── hooks/ # useBootSequence, useIsMobile, useMarketplaceSync
|
||||
│ │ ├── plugins/ # PluginManager, PluginRegistry, PluginManifest,
|
||||
│ │ │ │ loadPluginFromManifest, validateManifest, InstalledPluginsLoader
|
||||
│ │ │ └── loaders/ # mapJsonToEntities (Legacy loaders like DeclarativePlugin are deprecated)
|
||||
│ │ └── state/ # Zustand store + slices (config, data, globe, layers, timeline, ui, etc.)
|
||||
│ ├── lib/ # auth, db, rateLimit, analytics, AIS stream, marketplace APIs
|
||||
│ ├── plugins/ # GeoJSON plugin registrations
|
||||
│ ├── styles/ # HUD animations CSS
|
||||
│ ├── types/ # GeoJSON types, Umami types
|
||||
│ └── generated/ # Prisma generated client (gitignored)
|
||||
├── local-plugins/ # Local sandbox for developing plugins (gitignored)
|
||||
├── packages/ # pnpm monorepo workspace packages
|
||||
│ ├── wwv-plugin-sdk/ # Plugin SDK: type definitions, manifest schema
|
||||
│ ├── wwv-plugin-aviation/
|
||||
│ ├── wwv-plugin-maritime/
|
||||
│ ├── wwv-plugin-wildfire/
|
||||
│ ├── wwv-plugin-borders/
|
||||
│ ├── wwv-plugin-camera/
|
||||
│ ├── wwv-plugin-military-aviation/
|
||||
│ ├── wwv-plugin-satellite/
|
||||
│ ├── wwv-plugin-iranwarlive/ # Standalone plugin with custom endpoints
|
||||
│ └── wwv-plugin-{airports,embassies,lighthouses,nuclear,seaports,spaceports,volcanoes}/
|
||||
├── prisma/ # schema.prisma, migrations/
|
||||
├── public/ # Static assets, Cesium workers, plugin GeoJSON data
|
||||
├── scripts/ # Build scripts (copy-cesium, scaffold-osm-plugin, setup)
|
||||
├── data/ # PostgreSQL data volume (gitignored)
|
||||
├── Dockerfile # Multi-stage production build
|
||||
├── docker-compose.yml # Main app + data engine runner + local seeders
|
||||
└── .agents/ # Agent documentation, rules, skills, workflows
|
||||
```
|
||||
|
||||
## Related Repositories
|
||||
|
||||
| Repo | Purpose |
|
||||
|---|---|
|
||||
| `worldwideview` | Main application (this repo) |
|
||||
| `wwv-data-engine` | Generic data engine runner (PUBLIC, runs via Docker) |
|
||||
| `wwv-seeders-community` | Open-source community seeders (PUBLIC) |
|
||||
| `wwv-seeders-private` | Proprietary seeder scripts (PRIVATE, downloaded in prod) |
|
||||
| `worldwideview-marketplace` | Plugin marketplace web app |
|
||||
| `worldwideview-plugins` | Published npm plugin packages (frontend source) |
|
||||
| `worldwideview-web` | Marketing / landing page |
|
||||
@@ -1,7 +1,6 @@
|
||||
---
|
||||
trigger: testing
|
||||
description: Guidelines and architecture for the Playwright End-to-End (E2E) testing infrastructure.
|
||||
globs:
|
||||
paths:
|
||||
- "tests/**"
|
||||
- "public/e2e-fixtures/**"
|
||||
- "playwright.config.ts"
|
||||
@@ -38,3 +37,9 @@ E2E tests require an authenticated user to access core application features. We
|
||||
|
||||
> [!WARNING]
|
||||
> If you encounter flaky tests or `ECONNREFUSED` errors during Playwright runs, check if the local Next.js dev server or the Docker engine stack is competing for ports (e.g., port 5432 or 3000). Ensure `pnpm run dev:backends` is running and stable before launching the test suite.
|
||||
|
||||
## 6. Execution Environment & Tooling Limitations
|
||||
The development environment operates on **Windows PowerShell**. Agents MUST adhere to the following strict execution rules when running commands or interacting with the testing infrastructure:
|
||||
- **No Double Ampersands (`&&`)**: Standard Windows PowerShell (prior to v7) does not support the `&&` operator. Use the semicolon (`;`) to chain commands, or rely on `pnpm` package.json scripts which manage cross-platform execution properly.
|
||||
- **Avoid Non-existent Database CLI Commands**: Do not attempt to use raw `pg` or `psql` commands unless explicitly verified to exist in the path. Instead, use Prisma (`npx prisma studio`, `npx prisma migrate`) or Docker executions (`docker exec -it wwv-db psql ...`) for database interactions.
|
||||
- **Creating Test Plugins**: You will repeatedly need to create mock test plugins for verifying different platform features (e.g. bottom-panel resizing, new UI widgets). When doing so, you MUST review this `e2e-testing.md` file to ensure compliance with the `PluginManager` strict interface rules (implementing `getPollingInterval`, `fetch`, and `renderEntity`).
|
||||
@@ -1,34 +0,0 @@
|
||||
---
|
||||
trigger: model_decision
|
||||
description: A comprehensive guide to the WorldWideView ecosystem repositories in the local C:\dev environment. Use this to determine which repository to edit based on the feature being developed.
|
||||
---
|
||||
|
||||
# Ecosystem Repositories & Development Structure
|
||||
|
||||
The WorldWideView platform is not a single monolith; it is distributed across several repositories. In the local development environment, these repositories are organized as sibling directories under `C:\dev\`.
|
||||
|
||||
If you are asked to implement a feature or fix a bug, you **MUST** determine the correct repository to edit before writing code.
|
||||
|
||||
## Ecosystem Map (C:\dev\)
|
||||
|
||||
| Repository Folder | Purpose & When to Edit |
|
||||
|---|---|
|
||||
| **`worldwideview`** | The main application, Next.js frontend, Cesium globe, UI components, and the core plugin SDK. **Edit here** for anything related to the UI, state, map rendering, or built-in plugin frontend configurations. |
|
||||
| **`wwv-data-engine`** | The V2 Data Engine (Host Environment) that runs the seeders. **Edit here** if you need to modify how the engine parses WebSocket streams, implements REST APIs, downloads seeder bundles, or handles Redis caching. |
|
||||
| **`wwv-seeders`** | The community (public) data seeders. **Edit here** to create or modify background polling scripts (e.g. `aviation.ts`, `wildfire.ts`) that fetch data from public APIs and normalize it into `GeoEntity` arrays. |
|
||||
| **`wwv-seeders-private`** | The proprietary (private) data seeders. **Edit here** for closed-source, premium, or high-security data ingestion scripts. |
|
||||
| **`worldwideview-marketplace`** | The Plugin Marketplace web application. **Edit here** if you are modifying the platform where users browse, purchase, or manage plugin installations. |
|
||||
| **`worldwideview-plugins`** | Independent repository for published npm plugin packages (typically frontend source bundles). |
|
||||
| **`worldwideview-web`** | The marketing site, landing pages, and documentation. |
|
||||
| **`wwv-test`** | A testing ground repository (e.g., for docker-compose setups, scratch testing). |
|
||||
|
||||
## Cross-Repository Workflows
|
||||
|
||||
1. **Adding a New Data Source:**
|
||||
- Write the backend fetcher inside `C:\dev\wwv-seeders` (or `private`).
|
||||
- Write the frontend plugin interface inside `C:\dev\worldwideview` (or dynamically loaded via `worldwideview-plugins`).
|
||||
2. **Fixing Real-Time Streaming Issues:**
|
||||
- Investigate `C:\dev\worldwideview` (for frontend `WsClient` or `DataBus`).
|
||||
- Investigate `C:\dev\wwv-data-engine` (for backend Fastify websocket broadcasting).
|
||||
3. **Pnpm Workspaces:**
|
||||
- The Data Engine V2 automatically combines `community` and `private` seeders at runtime using pnpm workspaces. When testing seeders locally, refer to `C:\dev\worldwideview\local-seeders`.
|
||||
@@ -1,17 +0,0 @@
|
||||
# Environment Variables
|
||||
|
||||
| Variable | Required | Description |
|
||||
|---|---|---|
|
||||
| `DATABASE_URL` | Yes | PostgreSQL connection string |
|
||||
| `AUTH_SECRET` | Yes | JWT signing secret (generate with `openssl rand -hex 32`) |
|
||||
| `NEXT_PUBLIC_CESIUM_ION_TOKEN` | No | Cesium Ion access token |
|
||||
| `NEXT_PUBLIC_BING_MAPS_KEY` | No | Bing Maps imagery |
|
||||
| `NEXT_PUBLIC_GOOGLE_MAPS_API_KEY` | No | Google 3D Tiles |
|
||||
| `NEXT_PUBLIC_WWV_EDITION` | No | `local` / `cloud` / `demo` (default: `local`) |
|
||||
| `NEXT_PUBLIC_WWV_PLUGIN_DATA_ENGINE_URL` | No | Override engine WebSocket URL (default: cloud) |
|
||||
| `OPENSKY_CREDENTIALS` | No | Comma-separated `id:secret` pairs for credential rotation |
|
||||
| `WWV_BRIDGE_TOKEN` | No | Shared secret for marketplace → WWV install bridge |
|
||||
| `WWV_DEMO_ADMIN_SECRET` | No | Demo edition admin password |
|
||||
| `IRANWARLIVE_BACKEND_URL` | No | Override for IranWarLive custom backend URL |
|
||||
|
||||
Secrets go in `.env.local` (gitignored). Non-secrets go in `.env` (committed).
|
||||
@@ -0,0 +1,74 @@
|
||||
# Garbage Collection Policy
|
||||
|
||||
## Purpose
|
||||
|
||||
The Garbage Collector (GC) is a daily Haiku-model agent that keeps the codebase clean. It detects stale TODOs, deprecated patterns, and architectural drift, then either applies a small mechanical fix (Tier A → draft PR) or files a report for human decision (Tier B → GitHub Issue). The GC **never makes architectural decisions** and **never auto-merges** anything.
|
||||
|
||||
## Two-tier output model
|
||||
|
||||
| Tier | Criteria | Output |
|
||||
|---|---|---|
|
||||
| **A — Mechanical** | Safe, codemod-like, no architectural judgement required | Draft PR with code change |
|
||||
| **B — Judgement** | Requires human architectural decision or context | GitHub Issue, no code |
|
||||
|
||||
When unsure of the tier, escalate to Tier B. Never attempt a refactor that requires understanding business intent.
|
||||
|
||||
## How the GC works
|
||||
|
||||
1. `scripts/gc-scan.mjs` runs first — deterministic shell-based detectors, zero cost, emits `gc-findings.json`.
|
||||
2. The Haiku agent reads `gc-findings.json` and the policy below. It **does not free-scan the codebase** — it only triages the pre-computed findings list.
|
||||
3. The agent creates draft PRs and Issues per the caps and guard rails below.
|
||||
|
||||
## Approved finding types (from gc-scan.mjs)
|
||||
|
||||
| Type | Tier | Description |
|
||||
|---|---|---|
|
||||
| `stale-todo` | A | TODO/FIXME/HACK/XXX comment older than 90 days, or referencing a closed issue |
|
||||
| `anti-pattern` (mdc-ref) | A | `.mdc` file reference — must be `.md` |
|
||||
| `anti-pattern` (console-log) | A | Stray `console.log(` in `.ts`/`.tsx` files |
|
||||
| `anti-pattern` (ts-ignore) | A | `@ts-ignore` suppressing a real type error |
|
||||
| `anti-pattern` (ts-nocheck) | A | `@ts-nocheck` disabling all type checking |
|
||||
| `anti-pattern` (hardcoded-url) | B | Hardcoded `localhost:5001`/`5000` engine URL |
|
||||
| `anti-pattern` (deprecated) | B | `@deprecated` symbol still active in production code |
|
||||
| `oversized-file` | B | Source file exceeding ~350 lines |
|
||||
| `orphaned-rule-ref` | B | Rule file references a path that no longer exists |
|
||||
| `outdated-dep` | B | Dependency behind latest version |
|
||||
|
||||
## PR guard rails (mandatory — no exceptions)
|
||||
|
||||
- All PRs are **DRAFT**. Never mark ready-for-review. Never auto-merge.
|
||||
- Label every PR and Issue `gc-bot`.
|
||||
- **Max 3 PRs per run. Max 5 Issues per run.**
|
||||
- **Max ~150 changed lines per PR.** One concern per PR.
|
||||
- Branch naming: `gc/<patternId-or-type>-<git-short-sha>` (e.g. `gc/console-log-a3f1b2c`)
|
||||
- Before creating anything: check open `gc-bot` PRs and Issues for the same concern — skip if already covered.
|
||||
- Commit prefix: `chore:` for removal/cleanup, `refactor:` for structural fixes. Both are patch-level per the project `/commit` rule.
|
||||
- Every PR description must include: what changed · which detector flagged it · which rule it violates · how to verify the fix is correct.
|
||||
|
||||
## Never-touch list (absolute — the agent must refuse)
|
||||
|
||||
- `prisma/migrations/**` — migrations are irreversible
|
||||
- `pnpm-lock.yaml` — lockfile integrity
|
||||
- `.env`, `.env.local`, `.env.*`, any file containing secrets or tokens
|
||||
- Generated assets: `public/cesium/**`, `.next/**`, `node_modules/**`
|
||||
- Large seed files: `packages/*/data/**`, `local-seeders/**`
|
||||
- Binary assets: images, videos, fonts, `.db` files
|
||||
- `local-scripts/` — scratch / one-off scripts, not subject to conventions
|
||||
|
||||
## Dry-run mode
|
||||
|
||||
When `DRY_RUN=true` (set in the workflow dispatch input):
|
||||
|
||||
- Post one summary comment on the tracking Issue (`[gc-bot] Daily Scan Reports`). Create that Issue if it does not exist (label: `gc-bot`).
|
||||
- List every finding with tier, file, line, description.
|
||||
- **Do not create any PRs or Issues.**
|
||||
- Use dry-run for the first 3–5 days after deployment to validate finding quality before enabling normal mode.
|
||||
|
||||
## Idempotency rules
|
||||
|
||||
A finding is already handled if **either** of these is true:
|
||||
|
||||
1. A remote branch matching `gc/<same-patternId-or-type>-*` exists (`git branch -r --list 'origin/gc/<type>-*'`).
|
||||
2. An open PR or Issue labelled `gc-bot` already covers the same file + concern.
|
||||
|
||||
Skip handled findings without error or noise.
|
||||
@@ -1,6 +1,8 @@
|
||||
---
|
||||
trigger: model_decision
|
||||
description: Guidelines for the WorldwideView plugin marketplace, database interactions, and dynamic plugin installation.
|
||||
description: Guidelines for the WorldWideView plugin marketplace, database interactions, PKCE auth flow, and dynamic plugin installation.
|
||||
paths:
|
||||
- "src/lib/marketplace/**/*"
|
||||
- "src/app/api/marketplace/**/*"
|
||||
---
|
||||
|
||||
# Marketplace Architecture
|
||||
@@ -16,6 +18,18 @@ Plugins from the marketplace use the `bundle` format and are imported at runtime
|
||||
- `pluginManager.loadFromManifest()` validates and registers these plugins.
|
||||
- Ensure any schema changes to the marketplace tables follow the `database-migrations.md` rule.
|
||||
|
||||
## 4. Fresh-Install Seeding
|
||||
|
||||
Fresh installs (no rows in `InstalledPlugin`) auto-seed a starter set so the globe isn't empty on day one. The source of truth is the **signed verified registry** (`marketplace.worldwideview.dev/api/registry`, loaded by `registryClient.getVerifiedPluginIds()`).
|
||||
|
||||
- **No hard-coded plugin lists.** Publishing a plugin to the verified registry is what makes it part of the fresh-install starter set.
|
||||
- **Idempotent**: a `defaults_seeded` row in the `Setting` table prevents re-runs. If the registry is unreachable on first attempt, the guard is NOT set — the next request retries.
|
||||
- **Existing instances** with `defaults_seeded=true` are untouched. To pull in newly-verified plugins, users install via the marketplace UI.
|
||||
- **Demo edition** uses an independent path (`NEXT_PUBLIC_DEMO_DEFAULT_PLUGINS` env var, handled in `AppShell.tsx` and `useMarketplaceSync.ts`) — not this seeder.
|
||||
|
||||
> [!CAUTION]
|
||||
> Do not reintroduce a static `DEFAULT_PLUGIN_IDS` constant or any other hard-coded plugin list. That drifted from npm reality, caused 404s for unpublished IDs, and conflated "verified" with "auto-installed."
|
||||
|
||||
## Current Implementation State
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
---
|
||||
trigger: model_decision
|
||||
description: Strict rules for operating within the pnpm monorepo workspace environment structure across frontend and backend services.
|
||||
globs: ""
|
||||
paths:
|
||||
- "packages/**/*"
|
||||
- "pnpm-workspace.yaml"
|
||||
- "local-plugins/**/*"
|
||||
---
|
||||
|
||||
# Monorepo Workflow Guidelines
|
||||
@@ -13,7 +15,7 @@ Strict rules for operating within the `pnpm` monorepo workspace environment stru
|
||||
|
||||
- The Next.js frontend is located at root `.`.
|
||||
- Individual standalone plugins are located at `packages/wwv-plugin-[name]`.
|
||||
- For heavy plugin processing, data engine seeders are located at `local-seeders/community/[name]` or `local-seeders/private/[name]`.
|
||||
- For heavy plugin processing, data engine seeders are located at `local-seeders/community/[name]` or `local-seeders/private/[name]`. **These are separate git clones** (`github.com/silvertakana/wwv-seeders` and `wwv-seeders-private` respectively) — `pnpm install` from the main repo does NOT pull seeder code. Run `git pull` inside each clone to get upstream changes.
|
||||
|
||||
## Critical Workspace Rule
|
||||
|
||||
|
||||
@@ -1,120 +0,0 @@
|
||||
---
|
||||
trigger: model_decision
|
||||
description: High-level platform goals, product vision, business model, multi-repository layout, and the Edition System.
|
||||
---
|
||||
|
||||
# WorldWideView — Platform Architecture
|
||||
|
||||
|
||||
> **This folder is the canonical source of truth for the project. It is NOT committed to git.**
|
||||
> It contains live architectural decisions, future plans, and operational knowledge.
|
||||
|
||||
---
|
||||
|
||||
> [!TIP]
|
||||
> **For the fundamental system architecture, component layout, and data pipelines, please read [`docs/ARCHITECTURE.md`](../../../docs/ARCHITECTURE.md) first.**
|
||||
> This file focuses strictly on the advanced business vision, multi-repository layout, and the Edition System.
|
||||
|
||||
## Product Vision & Business Model
|
||||
|
||||
WorldWideView operates on a **VS Code distribution model**. It is a visualization platform, not a compute provider. Plugin authors bring their own backends to display real-time geospatial intelligence.
|
||||
|
||||
---
|
||||
|
||||
## Repository Structure
|
||||
|
||||
Five repositories, modelled after the n8n pattern:
|
||||
|
||||
| Repo | License | Purpose |
|
||||
|---|---|---|
|
||||
| `silvertakana/worldwideview` | Elastic License 2.0 | Core 3D globe app (Next.js + CesiumJS + Prisma) |
|
||||
| `silvertakana/wwv-data-engine` | Open Source | Generic runner (Fastify + Redis + WS) |
|
||||
| `silvertakana/wwv-seeders-community` | Open Source | Open-source community seeders |
|
||||
| `silvertakana/wwv-seeders-private` | **Private** | Proprietary seeder scripts (aviation, maritime, etc.) |
|
||||
| `silvertakana/worldwideview-marketplace` | Open Source | Plugin catalog, signed registry, admin UI |
|
||||
| `silvertakana/worldwideview-plugins` | Open Source | Published plugin frontend source |
|
||||
| `silvertakana/worldwideview-web` | Open Source | Landing page, docs, static content |
|
||||
| `silvertakana/worldwideview-cloud` | **Private** | Cloud deployment config — Docker Compose, nginx, provisioning scripts |
|
||||
| `silvertakana/plugin-sdk` | MIT | `@worldwideview/plugin-sdk` — shared types for repos + 3rd-party authors |
|
||||
|
||||
**n8n Parallel:**
|
||||
| n8n | WorldWideView |
|
||||
|---|---|
|
||||
| `n8n-io/n8n` | `silvertakana/worldwideview` |
|
||||
| `n8n-io/n8n-cloud` (private) | `silvertakana/worldwideview-cloud` (private) |
|
||||
| `n8n.io` landing | `worldwideview.dev` (static on Vercel) |
|
||||
| `app.n8n.cloud` dashboard | `app.worldwideview.dev` |
|
||||
| `[user].app.n8n.cloud` | `[user].app.worldwideview.dev` |
|
||||
| `@n8n/workflow` npm | `@worldwideview/plugin-sdk` npm |
|
||||
|
||||
---
|
||||
|
||||
## Domain Architecture
|
||||
|
||||
| URL | What | Stack |
|
||||
|---|---|---|
|
||||
| `worldwideview.dev` | Static marketing/landing | Next.js (static export) on Vercel |
|
||||
| `app.worldwideview.dev` | Auth, accounts, dashboard | Next.js + Supabase Auth |
|
||||
| `[user].app.worldwideview.dev` | User's cloud WWV instance | Next.js (multi-tenant, RLS) |
|
||||
| `marketplace.worldwideview.dev` | Plugin catalog, publishing, install | Next.js (SSO via WorldWideView auth) |
|
||||
| `demo.worldwideview.dev` | Public demo — pre-configured, read-only | Next.js (WWV app) |
|
||||
| `docs.worldwideview.dev` | Documentation | TBD (Mintlify/Nextra) |
|
||||
| `status.worldwideview.dev` | Uptime / incident | Uptime Kuma |
|
||||
| `api.worldwideview.dev` | Built-in data services (aviation, maritime) | Next.js API routes or standalone |
|
||||
| `cdn.worldwideview.dev` | Plugin bundle storage | Cloudflare R2 |
|
||||
|
||||
**Reserved subdomains:** `www`, `app`, `api`, `demo`, `marketplace`, `docs`, `status`, `admin`, `cdn`, `blog`, `changelog`
|
||||
|
||||
---
|
||||
|
||||
## Infrastructure
|
||||
|
||||
All on **Coolify** running on a repurposed **ThinkPad T480s** (i5-8350U, 16GB RAM, 256GB NVMe, Ubuntu). Zero monthly hosting cost.
|
||||
|
||||
```
|
||||
ThinkPad T480s (home server, $0/mo) Supabase (hosted)
|
||||
├── Coolify ──→ ├── PostgreSQL (cloud DB)
|
||||
│ ├── worldwideview.dev (landing, Vercel) ├── Auth (GoTrue)
|
||||
│ ├── app.worldwideview.dev (auth/dashboard) └── Storage (file uploads)
|
||||
│ ├── WWV Cloud App (Docker)
|
||||
│ ├── Marketplace App (Docker) Cloudflare (free)
|
||||
│ ├── Demo Instance (Docker) ├── DNS + wildcard routing
|
||||
│ ├── api.worldwideview.dev ├── CDN caching
|
||||
│ ├── Uptime Kuma ├── DDoS protection
|
||||
│ └── Plausible Analytics └── R2 (plugin bundle CDN)
|
||||
└── Ubuntu Server
|
||||
```
|
||||
|
||||
**CI/CD:** Push to `silvertakana/worldwideview` → GitHub Actions builds Docker image → pushes to `ghcr.io/silvertakana/worldwideview:latest` → Coolify webhook triggers rolling restart.
|
||||
|
||||
**Monitoring:** Uptime Kuma (all subdomains), Plausible/Umami analytics.
|
||||
|
||||
---
|
||||
|
||||
## Business Model
|
||||
|
||||
**Distribution platform, not compute provider.** Plugin authors handle their own backends.
|
||||
|
||||
| Revenue Stream | How |
|
||||
|---|---|
|
||||
| **Cloud hosting** | `[user].app.worldwideview.dev` — free/pro/enterprise tiers |
|
||||
| **Marketplace cut** | % of paid plugin subscriptions via Stripe Connect |
|
||||
| **Verified tier** | Plugin authors pay for review + verified badge |
|
||||
| **Pro/Enterprise license** | More quota, faster cache TTL, advanced features |
|
||||
| **Extension packs** | Curated bundles of related plugins |
|
||||
|
||||
Plugin authors can monetize independently (VS Code + GitHub Copilot model). Selling through the marketplace is **incentivized** (managed billing, featured placement, analytics) but not mandatory.
|
||||
|
||||
---
|
||||
|
||||
## Editions
|
||||
|
||||
Three editions; same codebase, gated by `NEXT_PUBLIC_WWV_EDITION`:
|
||||
|
||||
| Edition | Value | Database | Auth | Plugin Install |
|
||||
|---|---|---|---|---|
|
||||
| **Local** | `local` | PostgreSQL | Auth.js Credentials | Yes |
|
||||
| **Cloud** | `cloud` | PostgreSQL (Supabase) | Auth.js + Supabase | Yes |
|
||||
| **Demo** | `demo` | PostgreSQL (read-only) | Disabled | No |
|
||||
|
||||
Three thin adapter files handle edition differences: `src/core/auth.ts`, `src/core/storage.ts`, `src/core/tenant.ts`. Everything else is edition-unaware.
|
||||
@@ -1,6 +1,10 @@
|
||||
---
|
||||
trigger: model_decision
|
||||
description: The standard operating procedure for instantiating, modifying, and registering a new data source plugin within the engine.
|
||||
paths:
|
||||
- "src/core/plugins/**/*"
|
||||
- "packages/wwv-plugin-*/src/**/*"
|
||||
- "local-plugins/**/*"
|
||||
- "packages/wwv-plugin-sdk/src/**/*"
|
||||
---
|
||||
|
||||
# Plugin Architecture & Data Flow
|
||||
@@ -17,6 +21,59 @@ A valid plugin class MUST provide:
|
||||
3. `renderEntity(GeoEntity)` to determine visual style.
|
||||
4. `getPollingInterval()` (defaults fallback securely to standard store config).
|
||||
|
||||
## Plugin Data Delivery Types
|
||||
|
||||
Plugins receive entity data in one of three modes. Choose the right mode before writing code — mixing them causes silent data loss.
|
||||
|
||||
| Mode | `getPollingInterval()` | `fetch()` | `mapWebsocketPayload()` | When to use |
|
||||
|---|---|---|---|---|
|
||||
| **REST-only** | `> 0` (ms) | Returns `GeoEntity[]` | Not needed | Static or slow-changing data (< every 30s). No seeder required. |
|
||||
| **WebSocket-only** | `0` | Return `[]` immediately | **Required** if seeder sends object payload | Live-streaming data from a seeder (satellites, AIS, flights) |
|
||||
| **Hybrid** | `> 0` | Returns initial snapshot | **Required** if seeder sends object payload | Needs both immediate data on load AND live updates |
|
||||
|
||||
### WebSocket-Only Pattern (most live-data plugins)
|
||||
|
||||
```typescript
|
||||
getPollingInterval(): number {
|
||||
return 0; // WS-only — do NOT call REST on enable
|
||||
}
|
||||
|
||||
async fetch(_timeRange: TimeRange): Promise<GeoEntity[]> {
|
||||
return []; // Initial data arrives via mapWebsocketPayload within seconds
|
||||
}
|
||||
|
||||
mapWebsocketPayload(payload: any, _existingEntities: GeoEntity[]): GeoEntity[] {
|
||||
// Transform raw engine payload → GeoEntity[]
|
||||
// payload shape depends on what the seeder calls setLiveSnapshot() with
|
||||
const items = payload?.items ?? (Array.isArray(payload) ? payload : []);
|
||||
return items.map((item: any): GeoEntity => ({
|
||||
id: `my-plugin-${item.id}`,
|
||||
pluginId: "my-plugin",
|
||||
latitude: item.lat,
|
||||
longitude: item.lon,
|
||||
altitude: item.alt ?? 0,
|
||||
timestamp: new Date(),
|
||||
label: item.name,
|
||||
properties: item,
|
||||
}));
|
||||
}
|
||||
```
|
||||
|
||||
> [!WARNING]
|
||||
> If `getPollingInterval()` returns `0` but the seeder sends an object payload, you **MUST** implement `mapWebsocketPayload`. Without it, `WsClient` drops the data silently. See `data-engine-architecture.md §7` for the exact rule.
|
||||
|
||||
### `mapWebsocketPayload` Signature
|
||||
|
||||
```typescript
|
||||
mapWebsocketPayload(payload: any, existingEntities: GeoEntity[]): GeoEntity[]
|
||||
```
|
||||
|
||||
- `payload` — raw value from `setLiveSnapshot()` in the seeder (whatever shape the seeder stores)
|
||||
- `existingEntities` — current entities in the store for this plugin (use for incremental updates)
|
||||
- Must return a **complete replacement** `GeoEntity[]` (not a diff)
|
||||
|
||||
---
|
||||
|
||||
## Plugin Architectures (Manifest Formats)
|
||||
|
||||
Plugins are defined via `PluginManifest` and operate on an **All-Bundle** architecture.
|
||||
@@ -52,6 +109,33 @@ All plugins MUST define their identity and compatibility via a `"worldwideview"`
|
||||
}
|
||||
```
|
||||
|
||||
### `peerDependencies` Rule for npm-Published Plugins
|
||||
|
||||
Plugins published to npm **MUST** declare the following as `peerDependencies`, not `dependencies`:
|
||||
|
||||
```json
|
||||
{
|
||||
"peerDependencies": {
|
||||
"@worldwideview/wwv-plugin-sdk": "*",
|
||||
"react": ">=19",
|
||||
"lucide-react": "*"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Also peer (never bundle): `react-dom`, `cesium`, `resium`, `zustand`.
|
||||
|
||||
Bundling these causes multiple React instances in the host app, breaking hooks (`Invalid hook call` at runtime).
|
||||
|
||||
### File Extension Rule
|
||||
|
||||
- Files containing **JSX** (any `<Component />` syntax, `return (<div>...)`) → must use `.tsx`
|
||||
- Files with no JSX (pure TypeScript, even importing React types) → use `.ts`
|
||||
|
||||
This is enforced by the TypeScript compiler. A `.ts` file with JSX will fail to build.
|
||||
|
||||
---
|
||||
|
||||
## The Registration Pipeline
|
||||
|
||||
> [!NOTE]
|
||||
@@ -78,9 +162,9 @@ DataBus.getInstance().emit('dataUpdated', {
|
||||
});
|
||||
```
|
||||
|
||||
## Local Plugin Development (Sandbox)
|
||||
## Local Plugin Development
|
||||
|
||||
To rapidly iterate on plugins without polluting the core monorepo `packages/` directory or git history, use the local devkit:
|
||||
`local-plugins/` is a **git clone of the canonical community plugin repo** (`github.com/silvertakana/wwv-plugins`), gitignored from the main `worldwideview` repo. It has its own remote — commits and pushes go upstream to that public repo, not to `worldwideview`. Run `cd local-plugins && git pull` before working to get the latest community plugins.
|
||||
|
||||
1. **Create**: Run `node packages/wwv-cli/dist/index.js create <name> --local` to scaffold a full plugin structure inside the `local-plugins/` directory.
|
||||
2. **Develop**: Running `pnpm dev` or `pnpm dev:all` automatically spawns the `dev:plugins` watcher. Any changes made to plugins in `local-plugins/` will be instantly rebuilt using Vite (externalizing large globals) and synced to `public/plugins-local/` for hot-reloading.
|
||||
@@ -208,7 +292,7 @@ When implementing the `token-exchange` flow or communicating across domains, all
|
||||
Starting in 2026, WorldWideView adopted the **Architect and Toolbox** paradigm using NPM global tools, ensuring a fully decoupled developer experience. Plugin repositories contain *pure code* with absolutely no platform hosting boilerplate (e.g. no embedded docker-compose files).
|
||||
|
||||
### The Developer Experience
|
||||
1. **Scaffold**: `node packages/wwv-cli/dist/index.js create <name> --local` (Creates sandbox inside `local-plugins/`)
|
||||
1. **Scaffold**: `node packages/wwv-cli/dist/index.js create <name> --local` (Creates plugin inside `local-plugins/` — the community plugin repo clone)
|
||||
2. **Install**: `pnpm install` (Links dependencies via workspace)
|
||||
3. **Develop**: `pnpm dev:all` (Starts frontend, data engine, and plugin watcher dynamically)
|
||||
|
||||
@@ -391,13 +475,107 @@ While avoiding monolithic coupling, WWV plans to implement the following high-UX
|
||||
|
||||
## Local Plugins & Seeders
|
||||
|
||||
### 1. Local Sandbox Workflow
|
||||
### 1. Local Plugin Workflow (`local-plugins/` — community plugin repo clone)
|
||||
`local-plugins/` is a git clone of `github.com/silvertakana/wwv-plugins` with its own remote. Pull latest before starting: `cd local-plugins && git pull`.
|
||||
- **Scaffold**: `node packages/wwv-cli/dist/index.js create` (creates inside `local-plugins/wwv-plugin-<name>` by default, or `packages/` if `--core` is used).
|
||||
- **Develop**: `pnpm dev` triggers hot-reloading via `dev:plugins` watch script.
|
||||
- **Publish**: `node packages/wwv-cli/dist/index.js publish <name> [--org <your-org>]` publishes the plugin from the project root. (No linking is needed; the sandbox natively functions in the workspace).
|
||||
- **Publish**: `node packages/wwv-cli/dist/index.js publish <name> [--org <your-org>]` publishes the plugin from the project root. Commit and push from inside `local-plugins/` to contribute back to the community repo.
|
||||
|
||||
### 2. Data Engine Seeders
|
||||
Seeders in `wwv-data-engine/src/seeders/` provide the backend data.
|
||||
- **Cron Seeder**: Uses `registerSeeder({ name: "plugin-id", cron: "..." })` and pushes to Redis via `setLiveSnapshot()`.
|
||||
- **Init Seeder**: High-frequency or persistent websockets via `init: () => void`.
|
||||
- **Constraint**: Seeder `name` MUST exactly match the frontend plugin `id`. Do not bundle workspace dependencies like `ws` or `zod` into the seeder `dist`.
|
||||
|
||||
---
|
||||
|
||||
## Plugin Bundle Footguns
|
||||
|
||||
### 1. CSP blocks CDN stylesheets -- use `?inline` + `<style>` injection
|
||||
|
||||
The host app's `style-src` policy includes `'unsafe-inline'` but does **not** include external CDN origins like `unpkg.com` or `cdn.jsdelivr.net`. Any plugin that loads CSS via a runtime `<link href="https://unpkg.com/...">` will have that stylesheet **silently blocked** by the browser -- no console error, just broken styling and broken layout (elements fall back to `position: static`).
|
||||
|
||||
**Wrong:**
|
||||
```typescript
|
||||
// In useEffect:
|
||||
link.href = "https://unpkg.com/gridstack@11/dist/gridstack.min.css";
|
||||
document.head.appendChild(link);
|
||||
```
|
||||
|
||||
**Correct -- bundle CSS as inline string and inject via `<style>` tag:**
|
||||
```typescript
|
||||
import gridstackCSS from "gridstack/dist/gridstack.min.css?inline";
|
||||
|
||||
// In useEffect:
|
||||
const style = document.createElement("style");
|
||||
style.textContent = gridstackCSS;
|
||||
document.head.appendChild(style);
|
||||
```
|
||||
|
||||
Vite's `?inline` suffix imports CSS as a plain string. The `<style>` tag is allowed by `'unsafe-inline'`. This is the only CSP-safe pattern for third-party CSS in plugin bundles.
|
||||
|
||||
---
|
||||
|
||||
### 2. `inlineDynamicImports: true` -- not `codeSplitting: false`
|
||||
|
||||
`codeSplitting: false` is **not a valid Rollup option**. It is silently ignored, and Rollup will still produce code-split chunks. The host can only load a single `frontend.mjs` -- any sibling chunk (e.g. `gridstack-XXXXX.js`) will 404.
|
||||
|
||||
**Wrong:**
|
||||
```js
|
||||
rollupOptions: {
|
||||
output: { codeSplitting: false } // silently ignored
|
||||
}
|
||||
```
|
||||
|
||||
**Correct:**
|
||||
```js
|
||||
rollupOptions: {
|
||||
output: { inlineDynamicImports: true } // prevents all code splitting
|
||||
}
|
||||
```
|
||||
|
||||
Both `vite.config.ts` (for manual `pnpm build`) and `scripts/sync-local-plugins.mjs` must use `inlineDynamicImports: true`.
|
||||
|
||||
---
|
||||
|
||||
### 3. `process.env.NODE_ENV` in CJS deps -- needs inline Rollup transform, not Vite `define`
|
||||
|
||||
CJS dependencies like `recharts`, `prop-types`, and `react-is` reference `process.env.NODE_ENV` inside their CommonJS module body. Vite's top-level `define: { 'process.env.NODE_ENV': '"production"' }` does NOT reach inside Rollup's `__commonJSMin()` wrappers -- those run after the `define` substitution phase.
|
||||
|
||||
**Wrong:**
|
||||
```js
|
||||
// In vite.config.ts or sync-local-plugins.mjs:
|
||||
define: { 'process.env.NODE_ENV': '"production"' } // doesn't reach CJS wrappers
|
||||
```
|
||||
|
||||
**Correct -- add an inline Rollup transform plugin inside `rollupOptions.plugins`:**
|
||||
```js
|
||||
rollupOptions: {
|
||||
plugins: [
|
||||
{
|
||||
name: 'replace-process-env',
|
||||
transform(code) {
|
||||
if (!code.includes('process.env.NODE_ENV')) return null;
|
||||
return {
|
||||
code: code.replace(/process\.env\.NODE_ENV/g, '"production"'),
|
||||
map: null,
|
||||
};
|
||||
},
|
||||
},
|
||||
// ... other plugins
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
This plugin runs on each module source before Rollup wraps it, so it correctly replaces `process.env.NODE_ENV` in CJS sub-dependencies.
|
||||
|
||||
---
|
||||
|
||||
### 4. Yahoo Finance and third-party data APIs -- CORS from the browser
|
||||
|
||||
Yahoo Finance's chart API (`query1.finance.yahoo.com`) does **not** return `Access-Control-Allow-Origin` headers. Direct `fetch()` from a plugin bundle running in the browser will be CORS-blocked.
|
||||
|
||||
**Architectural preference (in order):**
|
||||
1. **Best:** Have the wwv-data-engine seeder fetch the data server-side and stream it to the plugin via WebSocket -- no CORS issue.
|
||||
2. **Acceptable stopgap:** Use `corsproxy.io` relay: `fetch('https://corsproxy.io/?url=' + encodeURIComponent(apiUrl))`. This adds a third-party relay dependency.
|
||||
3. **Do not do:** Assume browser `fetch()` to third-party financial APIs will work -- most do not send CORS headers.
|
||||
@@ -1,25 +0,0 @@
|
||||
---
|
||||
trigger: model_decision
|
||||
description: Server development and debugging rules for the production/homelab server using SSH and Coolify MCP.
|
||||
---
|
||||
|
||||
# Server Management & Debugging
|
||||
|
||||
## 1. Coolify MCP (High-Level)
|
||||
Use the `coolify` MCP server for managed actions:
|
||||
- **Discovery**: `mcp_coolify_projects`, `mcp_coolify_environments`
|
||||
- **Inspection**: `mcp_coolify_application_logs`, `mcp_coolify_get_application`
|
||||
- **Actions**: `mcp_coolify_control` (restart, stop)
|
||||
|
||||
## 2. Direct SSH (Low-Level)
|
||||
For filesystem or network issues, use direct SSH to the production server:
|
||||
`ssh [email protected] "<command>"`
|
||||
|
||||
**Common Commands**:
|
||||
- `docker ps`
|
||||
- `docker logs --tail 100 <container_id>`
|
||||
- `df -h`
|
||||
- `top -b -n 1` (Never run interactive `top` or `nano` via agent commands).
|
||||
|
||||
## 3. Safety Precautions
|
||||
Always use non-interactive flags for SSH. Communicate clearly before executing high-risk actions like volume deletion or critical infrastructure restarts.
|
||||
@@ -1,378 +0,0 @@
|
||||
---
|
||||
trigger: model_decision
|
||||
description: Human-centered design principles, stakeholder map, and decision matrix.
|
||||
---
|
||||
|
||||
# Stakeholders & Human-Centered Design
|
||||
|
||||
|
||||
> [!IMPORTANT]
|
||||
> **This document is mandatory reading before any feature, UI, API, or architectural decision.**
|
||||
> Every line of code in this project ultimately serves a human being. The AI agent MUST identify which stakeholder(s) a change affects and design the solution around their needs, abilities, and constraints — not the other way around.
|
||||
|
||||
---
|
||||
|
||||
## Why This Document Exists
|
||||
|
||||
Software that doesn't consider its humans fails. Not technically — socially. A plugin API that's elegant internally but hostile to external developers will die with zero third-party plugins. A monetization tier that ignores what users actually value will generate zero revenue. A contribution process that assumes PhD-level Cesium knowledge will attract zero contributors.
|
||||
|
||||
**The directive is simple:** Before you write code, ask *"Who is this for, what do they need, and what will they actually experience?"*
|
||||
|
||||
---
|
||||
|
||||
## The Stakeholder Universe
|
||||
|
||||
WorldWideView is not a single-user tool. It is a **platform ecosystem** with at least nine distinct human roles, each with different goals, different technical abilities, different emotional states when they interact with the product, and different definitions of "success."
|
||||
|
||||
```
|
||||
┌──────────────────┐
|
||||
│ Owner / Founder │
|
||||
│ (silvertakana) │
|
||||
└────────┬─────────┘
|
||||
│ vision, architecture, deployment
|
||||
┌───────────────────┼───────────────────┐
|
||||
│ │ │
|
||||
┌──────┴──────┐ ┌───────┴───────┐ ┌───────┴───────┐
|
||||
│ Core Devs │ │ Contributors │ │ Plugin Devs │
|
||||
│ (team) │ │ (community) │ │ (3rd party) │
|
||||
└──────┬──────┘ └───────┬───────┘ └───────┬───────┘
|
||||
│ │ │
|
||||
└───────────┬───────┘ │
|
||||
│ build the product │ extend the product
|
||||
┌───────────┴────────────────────────────┘
|
||||
│
|
||||
┌──────┴──────────────────────────────────┐
|
||||
│ The Application │
|
||||
│ ┌────────┐ ┌────────┐ ┌───────────┐ │
|
||||
│ │ Demo │ │ Local │ │ Cloud │ │
|
||||
│ │Instance│ │Instance│ │ Instance │ │
|
||||
│ └───┬────┘ └───┬────┘ └─────┬─────┘ │
|
||||
└──────┼───────────┼─────────────┼────────┘
|
||||
│ │ │
|
||||
┌──────┴──┐ ┌─────┴────┐ ┌────┴─────┐
|
||||
│Casual │ │Power User│ │Paying │
|
||||
│Visitor │ │(self-host)│ │Customer │
|
||||
└─────────┘ └──────────┘ └────┬─────┘
|
||||
│
|
||||
┌────────┴────────┐
|
||||
│ Advertisers │
|
||||
│ (demo edition) │
|
||||
└─────────────────┘
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Stakeholder Profiles
|
||||
|
||||
### 1. Owner / Founder (silvertakana)
|
||||
|
||||
| Attribute | Description |
|
||||
|---|---|
|
||||
| **Role** | Solo founder, architect, deployer, and operator of the entire ecosystem |
|
||||
| **Goal** | Build a sustainable, revenue-generating geospatial intelligence platform that rivals WorldMonitor |
|
||||
| **Motivations** | Technical excellence, creative ownership, financial independence, community building |
|
||||
| **Technical Ability** | Expert — TypeScript, Next.js, CesiumJS, Docker, infrastructure, Prisma, AI-assisted development |
|
||||
| **Emotional State** | Ambitious but resource-constrained; every wasted hour counts double |
|
||||
| **Definition of Success** | Growing user base, marketplace with active plugin developers, recurring revenue, industry recognition |
|
||||
| **Pain Points** | Single point of failure for ops, deployment, and architecture decisions; time pressure; hosting cost sensitivity ($0/mo target) |
|
||||
| **Interaction Surface** | `.agents/` rules, ROADMAP.md, Coolify dashboard, code reviews, AI pair-programming sessions |
|
||||
|
||||
**Design implications:**
|
||||
- Automation is critical — CI/CD, self-healing databases, zero-config setup
|
||||
- AI agent rules must preserve the owner's vision even when the owner isn't in the conversation
|
||||
- Cost-efficient architecture (PostgreSQL, ThinkPad server, free-tier services) is a feature, not a compromise
|
||||
- Every architectural decision must consider the owner's ability to maintain it solo
|
||||
|
||||
---
|
||||
|
||||
### 2. Core Development Team (WWV Devs)
|
||||
|
||||
| Attribute | Description |
|
||||
|---|---|
|
||||
| **Role** | Trusted developers with direct commit access to the monorepo |
|
||||
| **Goal** | Ship features quickly without breaking existing functionality |
|
||||
| **Motivations** | Clean code, clear architecture, fast iteration, not getting paged at 2am |
|
||||
| **Technical Ability** | High — comfortable with TypeScript, Next.js App Router, Zustand, pnpm workspaces |
|
||||
| **Emotional State** | Productive when patterns are clear; frustrated by undocumented gotchas |
|
||||
| **Definition of Success** | PRs merged cleanly, features work on first deploy, zero regressions |
|
||||
| **Pain Points** | File bloat (>150 lines), implicit state dependencies, CesiumJS rendering quirks, Docker build complexity |
|
||||
| **Interaction Surface** | `src/core/`, `src/components/`, `packages/`, PR reviews, `pnpm dev` |
|
||||
|
||||
**Design implications:**
|
||||
- 150-line file limit is sacred — enforce it in every code change
|
||||
- Clear slice boundaries in Zustand store prevent cross-team conflicts
|
||||
- `AGENTS.md` and `.agents/` context must always be current so that AI-augmented devs have accurate context
|
||||
- Rendering rules (billboard vs. point, never mix properties) must be enforced systematically
|
||||
- Docker gotchas documented in `06-dev-workflows.md` prevent time-sink debugging
|
||||
|
||||
---
|
||||
|
||||
### 3. Open Source Contributors
|
||||
|
||||
| Attribute | Description |
|
||||
|---|---|
|
||||
| **Role** | External developers who fork, fix bugs, add features, or create plugins via PRs |
|
||||
| **Goal** | Contribute meaningfully without needing to understand the entire 50-package monorepo |
|
||||
| **Motivations** | Portfolio building, learning CesiumJS/geospatial tech, improving a tool they use, open source goodwill |
|
||||
| **Technical Ability** | **Variable** — ranges from junior devs submitting typo fixes to senior engineers contributing optimizations |
|
||||
| **Emotional State** | Enthusiastic but easily discouraged by onboarding friction; will abandon contribution if setup takes >15 minutes |
|
||||
| **Definition of Success** | PR accepted and merged; their name in the contributors list; feature actually ships |
|
||||
| **Pain Points** | Complex monorepo, CesiumJS learning curve, Elastic License 2.0 implications, unclear "where to start" |
|
||||
| **Interaction Surface** | `CONTRIBUTING.md`, `docs/SETUP.md`, `docs/PLUGIN_GUIDE.md`, GitHub Issues, PR templates |
|
||||
|
||||
**Design implications:**
|
||||
- **One-command setup** (`pnpm run setup && pnpm dev:all`) is non-negotiable — if it breaks, contributors leave
|
||||
- `CONTRIBUTING.md` must use `pnpm` (currently shows `npm` in places — this is a bug)
|
||||
- "Good first issue" labels on GitHub attract newcomers
|
||||
- Plugin creation is the #1 entry point for contributors — the scaffold script and Plugin Guide must be flawless
|
||||
- The Elastic License 2.0 must be clearly communicated (it's NOT fully open source — contributors need to understand what they're signing up for)
|
||||
|
||||
---
|
||||
|
||||
### 4. Third-Party Plugin Developers
|
||||
|
||||
| Attribute | Description |
|
||||
|---|---|
|
||||
| **Role** | External developers who build and publish plugins to the WorldWideView Marketplace |
|
||||
| **Goal** | Create a plugin that integrates their data source, potentially monetize it |
|
||||
| **Motivations** | Revenue (marketplace cut), reach (installed on many WWV instances), reputation, data evangelism |
|
||||
| **Technical Ability** | **Mid-to-high** — comfortable with TypeScript and npm, but NOT Cesium experts. They should never need to learn Cesium internals. |
|
||||
| **Emotional State** | Evaluating whether the platform is worth investing development time in. Extremely sensitive to DX friction. |
|
||||
| **Definition of Success** | Plugin published, visible in marketplace, installed by users, data renders correctly, optional revenue stream |
|
||||
| **Pain Points** | (1) Backend hosting burden — they need a VPS for active plugins (the "VPS Problem"), (2) No distributable mini-engine yet, (3) SDK docs may not cover edge cases, (4) Rendering bugs with billboard/point property mixing |
|
||||
| **Interaction Surface** | `@worldwideview/wwv-plugin-sdk`, `docs/PLUGIN_GUIDE.md`, `docs/creating-a-plugin.md`, marketplace submission UI, npm publishing |
|
||||
|
||||
**Design implications:**
|
||||
- The Plugin SDK is the **#1 most important public API surface** — it must be impeccably documented, versioned, and stable
|
||||
- `WorldPlugin` interface changes are breaking changes that affect real people with real published packages
|
||||
- Three plugin formats (Declarative, Static, Code Bundle) exist specifically to lower the barrier:
|
||||
- **Declarative** = zero code (JSON only) — anyone with a data URL can create a plugin
|
||||
- **Static** = GeoJSON file + manifest — data analysts who aren't developers
|
||||
- **Code Bundle** = full TypeScript — professional developers
|
||||
- The future **Mini-Engine Docker image** (§3 of `03-plugin-system.md`) is critical for reducing the VPS burden
|
||||
- Rendering must be abstracted — plugin devs define `renderEntity()`, and the engine handles GPU batching
|
||||
- Error messages from the plugin lifecycle must be clear, not cryptic Cesium stack traces
|
||||
- Marketplace analytics (install counts, usage) are what keep plugin developers motivated
|
||||
|
||||
---
|
||||
|
||||
### 5. Casual Visitors (Demo Users)
|
||||
|
||||
| Attribute | Description |
|
||||
|---|---|
|
||||
| **Role** | Anonymous visitors who land on `demo.worldwideview.dev` — no account, no setup |
|
||||
| **Goal** | Explore the globe, see cool real-time data, understand what WorldWideView is |
|
||||
| **Motivations** | Curiosity, news events (war, natural disasters, flight tracking), linked from social media or Reddit |
|
||||
| **Technical Ability** | **Low to none** — they don't know what ADS-B or GeoJSON means. They just want to see planes on a globe. |
|
||||
| **Emotional State** | Impatient. They will leave within 10 seconds if the globe doesn't load or the UI is confusing. |
|
||||
| **Definition of Success** | "Whoa, this is cool" → bookmark/share → return later → potentially convert to self-host or cloud user |
|
||||
| **Pain Points** | Slow boot time (Cesium asset loading), confusing UX, data not loading (API rate limits), ads disrupting experience |
|
||||
| **Interaction Surface** | Boot overlay, 3D globe, layer toggle panel, entity hover/click, info cards, timeline, ad strip |
|
||||
|
||||
**Design implications:**
|
||||
- **First 5 seconds are everything** — the boot overlay must feel cinematic, not broken
|
||||
- Pre-activate compelling default layers (aviation is the universal crowd-pleaser)
|
||||
- Globe interaction must work without instructions — left-click drag, scroll zoom, click entity
|
||||
- The "Why ads?" banner (`DemoAdStrip`) is a trust-building honesty moment — keep it human and transparent
|
||||
- Mobile layout must be flawless — many demo visitors come from social media on phones
|
||||
- No login walls, no setup wizards, no configuration prompts — demo is zero-friction
|
||||
- Performance on commodity hardware (integrated GPUs, 2017 laptops) must be acceptable
|
||||
- Error states must be invisible — if OpenSky is down, the layer just shows fewer planes, not an error dialog
|
||||
|
||||
---
|
||||
|
||||
### 6. Self-Hosted Power Users (Local Edition)
|
||||
|
||||
| Attribute | Description |
|
||||
|---|---|
|
||||
| **Role** | Technical users who run WorldWideView on their own hardware (Raspberry Pi, home server, VPS) |
|
||||
| **Goal** | Full control over their own geospatial intelligence dashboard, no cloud dependency |
|
||||
| **Motivations** | Privacy, customization, data sovereignty, OSINT hobbyism, professional intelligence work |
|
||||
| **Technical Ability** | **High** — comfortable with Docker, environment variables, CLI tools, possibly contributing plugins |
|
||||
| **Emotional State** | Empowered but demanding. They chose self-hosting for a reason — they expect it to work without phoning home. |
|
||||
| **Definition of Success** | Instance running 24/7, plugins installed and polling reliably, data persisted locally, zero external dependencies |
|
||||
| **Pain Points** | Docker build complexity, PostgreSQL connection pooling issues, Cesium token setup, Prisma migration gotchas, plugin data not loading |
|
||||
| **Interaction Surface** | `docker-compose.yml`, `.env.local`, Setup Wizard, Layers Panel, Config Panel, Marketplace Bridge, `pnpm run dev:all` |
|
||||
|
||||
**Design implications:**
|
||||
- **Zero-config first run** — `pnpm run setup && pnpm dev` or `docker-compose up` must "just work"
|
||||
- The Setup Wizard (Cesium token prompt) is the ONLY mandatory configuration step — minimize it
|
||||
- PostgreSQL must handle concurrent reads from the app + data engine efficiently
|
||||
- Self-hosted users are the most likely to become contributors — treat their issues as high-priority
|
||||
- Data engine self-healing (fallback seeds) ensures restarts don't lose data
|
||||
- Offline capability is a differentiator — cached entities in IndexedDB survive network outages
|
||||
- `NEXT_PUBLIC_WWV_EDITION=local` must be the default, most-tested path
|
||||
|
||||
---
|
||||
|
||||
### 7. Paying Customers (Cloud Pro/Enterprise)
|
||||
|
||||
| Attribute | Description |
|
||||
|---|---|
|
||||
| **Role** | Users or organizations paying for `[user].app.worldwideview.dev` — the revenue engine |
|
||||
| **Goal** | Reliable, always-on geospatial intelligence with history, higher rate limits, and team access |
|
||||
| **Motivations** | Professional OSINT, military/defense analysis, logistics monitoring, journalism, corporate security |
|
||||
| **Technical Ability** | **Variable** — from journalists who just need a globe to security analysts who want API access |
|
||||
| **Emotional State** | **Paying customers have the lowest tolerance for bugs.** They expect enterprise-grade uptime and support. |
|
||||
| **Definition of Success** | Data is live, history works, team members can access, exports work, it doesn't go down |
|
||||
| **Pain Points** | Downtime, stale data, missing features compared to competitors, unclear what "Pro" actually gives them |
|
||||
| **Interaction Surface** | Cloud dashboard, license key input, plugin marketplace, support channels, billing UI |
|
||||
|
||||
**Design implications:**
|
||||
- **Uptime is king** — Uptime Kuma monitoring, error alerting, and rollback procedures exist for this reason
|
||||
- Tier differentiation must be clear and valuable:
|
||||
- Free: 3 users, 500MB, 24h history
|
||||
- Pro: 20 users, 5GB, full history, snapshot capture
|
||||
- Enterprise: unlimited, 50GB+, custom domains
|
||||
- License key verification (RSA-signed JWT) prevents forgery but must not be onerous UX
|
||||
- RLS tenant isolation is non-negotiable — data leaks between tenants are existential
|
||||
- Response caching at the API proxy layer makes the $0/mo server viable for multiple tenants
|
||||
- The cloud edition must feel **identical** to local — same UI, same plugins, same experience
|
||||
|
||||
---
|
||||
|
||||
### 8. Advertisers (Demo Edition Revenue)
|
||||
|
||||
| Attribute | Description |
|
||||
|---|---|
|
||||
| **Role** | Google AdSense (programmatic) — automated ad placement on the demo instance |
|
||||
| **Goal** | Display relevant ads to engaged visitors, generate clicks/impressions |
|
||||
| **Motivations** | ROI on ad spend; relevant audience targeting |
|
||||
| **Technical Ability** | N/A — they interact through Google's ad platform, not with WWV directly |
|
||||
| **Emotional State** | N/A — algorithmic. But their platform (AdSense) has strict technical requirements. |
|
||||
| **Definition of Success** | Ads render correctly, non-intrusively, on viewable screen real estate |
|
||||
| **Pain Points** | AdSense script crashes on resize, ads failing to fill on localhost/tunnels, ads overlapping interactive content |
|
||||
| **Interaction Surface** | `DemoAdStrip.tsx`, `AdUnit.tsx`, Google AdSense publisher dashboard |
|
||||
|
||||
**Design implications:**
|
||||
- Ad strip is a **structurally separate sibling container** — never overlaps the globe viewport
|
||||
- Fixed-position elements (header, timeline, sidebars) use `--ad-strip-inset` CSS variable to avoid overlap
|
||||
- AdSense `push()` errors on resize are handled by fully unmounting ad units below 850px height
|
||||
- Ads are **demo edition only** — they never appear in local or cloud editions
|
||||
- The "Why ads?" banner is a conscious UX choice that builds trust with users and is dismissible
|
||||
- Ad revenue is a temporary bridge to sustainability, not the long-term business model
|
||||
|
||||
---
|
||||
|
||||
### 9. Data Source Providers (Upstream APIs)
|
||||
|
||||
| Attribute | Description |
|
||||
|---|---|
|
||||
| **Role** | External services that provide the raw data: OpenSky, AIS providers, NASA FIRMS, ACLED, CelesTrak, GPSJam, etc. |
|
||||
| **Goal** | Serve data within their rate limits and terms of service |
|
||||
| **Motivations** | Open data mission (NASA, CelesTrak), freemium conversion (OpenSky), research community |
|
||||
| **Technical Ability** | N/A — they expose APIs; WWV consumes them |
|
||||
| **Emotional State** | Hostile if rate-limited. Neutral if respected. |
|
||||
| **Definition of Success** | API consumers stay within rate limits, attribute correctly, and don't DDOS their endpoints |
|
||||
| **Pain Points** | Credential rotation failures (OpenSky), rate limit exhaustion, unattributed scraping |
|
||||
| **Interaction Surface** | Data Engine seeders, API route proxies, `OPENSKY_CREDENTIALS` rotation, `pollingIntervalMs` settings |
|
||||
|
||||
**Design implications:**
|
||||
- **Respect upstream rate limits** — this is an ethical and practical obligation
|
||||
- Credential rotation (`OPENSKY_CREDENTIALS` comma-separated pairs) prevents per-key throttling
|
||||
- The Data Engine's 5-minute Redis throttle (`setLiveSnapshot`) is specifically designed to stay within Upstash free-tier limits
|
||||
- API proxy caching (1000 users → 1 upstream request) is architecturally essential
|
||||
- Attribution (e.g., "Data: OpenSky Network") should be visible in entity detail panels
|
||||
- Graceful degradation when APIs go down — show cached data, not error modals
|
||||
|
||||
---
|
||||
|
||||
## The Stakeholder Decision Matrix
|
||||
|
||||
When making any decision, use this matrix to identify impact:
|
||||
|
||||
| Decision Area | Owner | Core Devs | Contributors | Plugin Devs | Casual Visitors | Power Users | Paying Customers | Advertisers | Data Providers |
|
||||
|---|---|---|---|---|---|---|---|---|---|
|
||||
| **Plugin SDK change** | ⚠️ | ⚠️ | ⬜ | 🔴 | ⬜ | ⬜ | ⬜ | ⬜ | ⬜ |
|
||||
| **UI/UX redesign** | ⚠️ | ⬜ | ⬜ | ⬜ | 🔴 | ⚠️ | 🔴 | ⚠️ | ⬜ |
|
||||
| **Rendering pipeline change** | ⚠️ | 🔴 | ⬜ | ⚠️ | ⚠️ | ⚠️ | ⚠️ | ⬜ | ⬜ |
|
||||
| **Database schema migration** | ⚠️ | ⚠️ | ⬜ | ⬜ | ⬜ | 🔴 | 🔴 | ⬜ | ⬜ |
|
||||
| **New data source plugin** | ✅ | ⬜ | ✅ | ⬜ | ✅ | ✅ | ✅ | ⬜ | ⚠️ |
|
||||
| **Pricing/tier change** | 🔴 | ⬜ | ⬜ | ⚠️ | ⬜ | ⚠️ | 🔴 | ⬜ | ⬜ |
|
||||
| **Ad placement change** | ⚠️ | ⬜ | ⬜ | ⬜ | ⚠️ | ⬜ | ⬜ | 🔴 | ⬜ |
|
||||
| **API rate limit adjustment** | ⬜ | ⬜ | ⬜ | ⬜ | ⬜ | ⬜ | ⚠️ | ⬜ | 🔴 |
|
||||
| **Marketplace policy** | 🔴 | ⬜ | ⬜ | 🔴 | ⬜ | ⬜ | ⚠️ | ⬜ | ⬜ |
|
||||
| **Docker/deployment change** | 🔴 | ⚠️ | ⬜ | ⬜ | ⬜ | 🔴 | ⚠️ | ⬜ | ⬜ |
|
||||
| **License change** | 🔴 | ⚠️ | 🔴 | 🔴 | ⬜ | ⚠️ | ⬜ | ⬜ | ⬜ |
|
||||
|
||||
**Legend:** 🔴 = Primary impact (design for this person) | ⚠️ = Secondary impact (consider carefully) | ✅ = Positive impact | ⬜ = Minimal/no impact
|
||||
|
||||
---
|
||||
|
||||
## The Golden Rules
|
||||
|
||||
### 1. Every Feature Has a Human
|
||||
|
||||
Before writing a single line of code, the AI agent MUST answer:
|
||||
- **WHO** is this for? (Name the stakeholder)
|
||||
- **WHY** do they need it? (What problem does it solve for them?)
|
||||
- **HOW** will they discover/use it? (What's their journey?)
|
||||
- **WHAT** happens when it breaks? (Graceful degradation plan)
|
||||
|
||||
### 2. Reduce Friction, Not Features
|
||||
|
||||
The most dangerous failure mode is building powerful systems with hostile interfaces. Apply the **Principle of Least Effort**:
|
||||
- Contributors: one-command setup, not a wiki page of prerequisites
|
||||
- Plugin devs: `renderEntity()` returns an object, not a Cesium Primitive
|
||||
- Casual visitors: zero onboarding, zero configuration
|
||||
- Power users: sensible defaults, optional configuration
|
||||
- Paying customers: it just works, always
|
||||
|
||||
### 3. Design for the Least Technical User in Each Cohort
|
||||
|
||||
| Cohort | Least Technical Member | Design Target |
|
||||
|---|---|---|
|
||||
| Plugin Developers | Data analyst who can write JSON | Declarative plugin format |
|
||||
| Contributors | Junior dev on their first open source PR | Scaffold scripts + clear CONTRIBUTING.md |
|
||||
| Casual Visitors | Non-technical person who followed a Twitter link | Auto-loading layers, intuitive globe controls |
|
||||
| Power Users | Sysadmin who can `docker-compose up` but doesn't know Next.js | Pre-built Docker images, `.env` only config |
|
||||
| Paying Customers | Journalist tracking a conflict | Clear UI, no jargon, exportable data |
|
||||
|
||||
### 4. Protect the Ecosystem Trust
|
||||
|
||||
The trust hierarchy is cryptographically enforced (Ed25519 signed registry), but trust is also social:
|
||||
- **Built-in plugins** must always work — they're the first impression
|
||||
- **Verified plugins** carry WorldWideView's reputation — review them seriously
|
||||
- **Unverified plugins** get a warning dialog — users make informed decisions
|
||||
- **Plugin developers** who see installs and analytics stay motivated
|
||||
- **Data providers** who aren't rate-limit abused will keep serving data
|
||||
|
||||
### 5. Revenue Serves Sustainability, Not Extraction
|
||||
|
||||
The business model exists to keep the project alive:
|
||||
- Ads on demo = temporary hosting cost recovery (transparent "Why ads?" banner)
|
||||
- Cloud Pro = value exchange (history, higher limits, team access)
|
||||
- Marketplace cut = sustainable ecosystem (Stripe Connect revenue split)
|
||||
- Plugin developer monetization = VS Code model (developers set their own prices)
|
||||
|
||||
Never design a feature that extracts value from users without returning it. The demo must always be useful, not crippled.
|
||||
|
||||
---
|
||||
|
||||
## Applying This Document
|
||||
|
||||
### For the AI Agent
|
||||
|
||||
When the agent is asked to implement a feature, modify architecture, or solve a bug, it MUST:
|
||||
|
||||
1. **Identify affected stakeholders** from the list above
|
||||
2. **Consider the least-technical user** in each affected cohort
|
||||
3. **Check the decision matrix** for impact severity
|
||||
4. **Apply the golden rules** to the implementation approach
|
||||
5. **Document stakeholder considerations** in PR descriptions and implementation plans
|
||||
|
||||
### For Human Developers
|
||||
|
||||
When reviewing PRs or proposing features, ask:
|
||||
- "Did we consider how this affects plugin developers?"
|
||||
- "Will a first-time contributor understand this?"
|
||||
- "Does this work on the demo without configuration?"
|
||||
- "Will this survive a Docker restart on the ThinkPad?"
|
||||
|
||||
---
|
||||
|
||||
## Version History
|
||||
|
||||
| Date | Change |
|
||||
|---|---|
|
||||
| 2026-04-05 | Initial stakeholder map created from comprehensive project research |
|
||||
@@ -1,7 +1,8 @@
|
||||
---
|
||||
trigger: glob
|
||||
description: Guidelines on managing the single source of truth across WorldWideView using Zustand, avoiding prop-drilling, and isolating UI rerenders.
|
||||
globs: "src/core/state/**/*, src/components/**/*"
|
||||
paths:
|
||||
- "src/core/state/**/*"
|
||||
- "src/components/**/*"
|
||||
---
|
||||
|
||||
# Zustand State Management
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
---
|
||||
trigger: model_decision
|
||||
description: Troubleshooting and debugging guidelines for WorldWideView, covering latency, logging, and namespace collisions.
|
||||
---
|
||||
|
||||
# Troubleshooting and Debugging
|
||||
|
||||
## 1. Plugin Data Latency
|
||||
If there is a noticeable delay (e.g., ~1 second) between enabling a plugin and the initial data arriving on the globe, **do not assume the UI is blocking**.
|
||||
- **WebSocket Handshake**: Initial latency is often caused by the time it takes to establish a new WebSocket connection to the engine's `/stream`.
|
||||
- **Upstream Cooldowns**: Plugins querying external providers (like OpenSky for `aviation`) have strict rate limits. If a snapshot returns a `404`, it might mean the seeder is in a cooldown period or hasn't successfully fetched data yet. This is expected behavior.
|
||||
- **Diagnosis**: Instrument the `DataBusSubscriber` and `WsClient` with timing logs (`performance.now()`) to track exactly where the bottleneck occurs (manifest discovery vs connection establishment vs first payload).
|
||||
|
||||
## 2. Log Verbosity and Structured Logging
|
||||
We employ a **structured logging strategy** in the frontend to reduce noise and improve readability.
|
||||
- **Rule**: Do not add excessive `console.log` statements that dump raw JSON payloads or stream contents directly to the console in core files like `WsClient.ts` or `PluginManager.ts`.
|
||||
- **Implementation**: If detailed logs are needed, use conditional debug levels or summarize the output (e.g., logging payload sizes or entity counts instead of the full object array). This ensures critical diagnostic information remains visible without overflowing the terminal.
|
||||
|
||||
## 3. Namespace Collisions
|
||||
If a plugin fails to load in the Data Engine with a `404` or `Error [ERR_MODULE_NOT_FOUND]` error during startup:
|
||||
- **Root Cause**: The seeder may exist simultaneously in both the `wwv-seeders-community` and `wwv-seeders-private` repositories.
|
||||
- **Resolution**: Seeders must have a unique namespace. Ensure that private plugins (e.g., `aviation`, `maritime`, `military-aviation`) are explicitly removed from the community repository to prevent workspace-level module resolution failures when the V2 engine attempts to load them. Private seeders take priority, but overlapping names will cause dependency conflicts.
|
||||
|
||||
## 4. Agent Execution Environments (Windows/PowerShell)
|
||||
When an AI agent or developer is executing CLI commands via tools in this project on Windows:
|
||||
- **Rule**: NEVER use the `&&` operator to chain commands in PowerShell. It will result in parser errors.
|
||||
- **Resolution**: Use sequential execution, run commands separately, or use PowerShell-safe chaining like `; if ($?) { }`.
|
||||
|
||||
## 5. Next.js vs. Undici Fetch Type Mismatches
|
||||
When implementing SSRF protections (e.g., DNS IP Pinning via custom `Dispatcher`), you will likely use `undici.Agent`.
|
||||
- **Root Cause**: Passing global Next.js `RequestInit` options directly into `undici.fetch` will throw strict TypeScript errors because the `BodyInit` and `RequestCache` signatures differ, and `dns.lookup` returns a generic `number` instead of exactly `4 | 6` for IP families.
|
||||
- **Resolution**: Strip out Next.js specific keys, explicitly cast `body` as `any`, and explicitly type `resolvedFamily: number` when interfacing between Next.js request streams and the `undici` library.
|
||||
@@ -0,0 +1,8 @@
|
||||
param([string]$worktreePath)
|
||||
# Convert Unix-style path (/c/dev/...) to Windows path (C:\dev\...) if needed
|
||||
if ($worktreePath -match '^/([a-zA-Z])/(.+)$') {
|
||||
$worktreePath = $matches[1].ToUpper() + ':/' + $matches[2]
|
||||
}
|
||||
$target = Join-Path $worktreePath '.planning'
|
||||
if (Test-Path $target) { Remove-Item $target -Force }
|
||||
New-Item -ItemType Junction -Path $target -Target 'C:\dev\wwv\.planning' | Out-Null
|
||||
@@ -0,0 +1,7 @@
|
||||
param([string]$worktreePath)
|
||||
# Convert Unix-style path (/c/dev/...) to Windows path (C:\dev\...) if needed
|
||||
if ($worktreePath -match '^/([a-zA-Z])/(.+)$') {
|
||||
$worktreePath = $matches[1].ToUpper() + ':/' + $matches[2]
|
||||
}
|
||||
$target = Join-Path $worktreePath '.planning'
|
||||
if (Test-Path $target) { Remove-Item $target -Force }
|
||||
@@ -5,7 +5,8 @@
|
||||
"permissions": {
|
||||
"allow": [
|
||||
"Read(src/**)",
|
||||
"Bash(npm test)"
|
||||
"Bash(npm test)",
|
||||
"Bash(node \"C:/Users/silve/.claude/hooks/claude-dir-guard.js\")"
|
||||
],
|
||||
"deny": [
|
||||
"Read(.env)",
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
---
|
||||
name: migrate-legacy-plugin
|
||||
description: Use when moving a WorldWideView plugin from packages/ (or ../worldwideview-plugins/packages/) to local-plugins/, converting legacy plugins to the new Engine & Payload architecture, or when a plugin hardcodes engine URLs, bundles Node.js built-ins, or uses import.meta.url for file paths inside Docker containers
|
||||
description: Use when moving a WorldWideView plugin from packages/ to local-plugins/ (the wwv-plugins community repo clone), converting legacy plugins to the new Engine & Payload architecture, or when a plugin hardcodes engine URLs, bundles Node.js built-ins, or uses import.meta.url for file paths inside Docker containers
|
||||
---
|
||||
|
||||
# Migrate Legacy Plugin to Modern Architecture
|
||||
|
||||
## Overview
|
||||
|
||||
Moves a WorldWideView plugin from the old `packages/` monorepo location (or the external `worldwideview-plugins` repository) into the `local-plugins/` directory (which is itself a publishable Git repository). Simultaneously fixes two **independent** concerns that legacy plugins always have:
|
||||
Moves a WorldWideView plugin from the old `packages/` monorepo location into the `local-plugins/` directory (which is a git clone of `github.com/silvertakana/wwv-plugins` — the canonical community plugin repo). Simultaneously fixes two **independent** concerns that legacy plugins always have:
|
||||
|
||||
1. **Frontend routing** — hardcoded engine URLs must be replaced with `resolveEngineUrl()`
|
||||
2. **Backend seeder build** — ESM bundling and container-aware file paths
|
||||
@@ -16,7 +16,7 @@ Moves a WorldWideView plugin from the old `packages/` monorepo location (or the
|
||||
|
||||
## When to Use
|
||||
|
||||
- Moving a plugin from `packages/wwv-plugin-<name>/` (or `../worldwideview-plugins/packages/wwv-plugin-<name>/`) to `local-plugins/wwv-plugin-<name>/`
|
||||
- Moving a plugin from `packages/wwv-plugin-<name>/` to `local-plugins/wwv-plugin-<name>/`
|
||||
- Plugin's `fetch()` hardcodes a URL like `https://dataengine.worldwideview.dev`
|
||||
- Plugin uses `this.context?.apiBaseUrl` instead of `resolveEngineUrl()`
|
||||
- Backend seeder crashes with `Dynamic require` or `ERR_INVALID_FILE_URL_PATH` in Docker
|
||||
@@ -38,7 +38,7 @@ Moves a WorldWideView plugin from the old `packages/` monorepo location (or the
|
||||
> ```
|
||||
> Example: `node scripts/migrate-plugin.mjs gps-jamming`
|
||||
>
|
||||
> The script will automatically copy the frontend plugin, inject peerDependencies, refactor `index.tsx` routing, fix the backend seeder's build settings and `SEEDERS_DIR` paths, and register the plugin in `defaultPlugins.ts`.
|
||||
> The script will automatically copy the frontend plugin, inject peerDependencies, refactor `index.tsx` routing, and fix the backend seeder's build settings and `SEEDERS_DIR` paths. (Fresh-install seeding no longer involves a hard-coded list — once published to npm with a valid `worldwideview` block, the plugin is registered via the signed verified registry.)
|
||||
> **You still need to run `pnpm install` and verify the builds manually as described below.**
|
||||
|
||||
> [!IMPORTANT]
|
||||
@@ -59,14 +59,13 @@ Copy the plugin from `packages/` (or the external plugins repo) to `local-plugin
|
||||
# From project root (if in local packages/)
|
||||
cp -r packages/wwv-plugin-<name> local-plugins/wwv-plugin-<name>
|
||||
|
||||
# OR from external plugins repository:
|
||||
cp -r ../worldwideview-plugins/packages/wwv-plugin-<name> local-plugins/wwv-plugin-<name>
|
||||
```
|
||||
|
||||
The `local-plugins/` directory is:
|
||||
- Part of the pnpm workspace (`pnpm-workspace.yaml` includes `local-plugins/*`)
|
||||
- Gitignored from the main worldwideview repo (it IS its own Git repo — `worldwideview-plugins`)
|
||||
- Gitignored from the main worldwideview repo — it IS its own git repo (`github.com/silvertakana/wwv-plugins`, the canonical community plugin repo)
|
||||
- Auto-discovered by the `dev:plugins` watcher during `pnpm dev`
|
||||
- Run `cd local-plugins && git pull` before working to fetch the latest community plugins
|
||||
|
||||
## Step 2: Fix Frontend Routing (getEngineUrl)
|
||||
|
||||
@@ -220,7 +219,7 @@ local-seeders/community/packages/gps-jamming/
|
||||
|
||||
After moving to `local-plugins/`, remove the old references:
|
||||
|
||||
- [ ] Delete `packages/wwv-plugin-<name>/` directory (or the source directory in `../worldwideview-plugins/packages/`)
|
||||
- [ ] Delete `packages/wwv-plugin-<name>/` directory
|
||||
- [ ] Remove from `transpilePackages` in `next.config.ts` (if present)
|
||||
- [ ] Remove path alias from `tsconfig.json` `paths` (if present)
|
||||
- [ ] Remove any registration in `AppShell.tsx` (now loaded dynamically)
|
||||
|
||||
@@ -0,0 +1,121 @@
|
||||
---
|
||||
name: worktree-bootstrap
|
||||
description: Create and fully bootstrap a WWV git worktree for isolated feature/debug work. Copies env vars, installs deps, generates Prisma client, and verifies the dev server boots before reporting ready.
|
||||
---
|
||||
|
||||
# Worktree Bootstrap
|
||||
|
||||
Use this skill when creating a new worktree for isolated debugging or feature work. Eliminates the repeated "missing .env.local" / "Prisma client not generated" failures.
|
||||
|
||||
## Steps
|
||||
|
||||
### 1. Create the worktree
|
||||
|
||||
From `C:\dev\wwv\worldwideview\`:
|
||||
|
||||
```powershell
|
||||
git-wt switch --create <branch-name> --yes
|
||||
```
|
||||
|
||||
This places the worktree at `C:\dev\wwv\worldwideview.<branch-name>\`.
|
||||
|
||||
### 2. Copy environment file
|
||||
|
||||
`.env` contains shared secrets (AUTH_SECRET, DATABASE_URL, etc.) that are gitignored and not present in new worktrees. Copy it:
|
||||
|
||||
```powershell
|
||||
Copy-Item C:\dev\wwv\worldwideview\.env C:\dev\wwv\worldwideview.<branch-name>\.env
|
||||
```
|
||||
|
||||
Verify required vars are present:
|
||||
|
||||
```powershell
|
||||
Select-String -Path C:\dev\wwv\worldwideview.<branch-name>\.env -Pattern "^AUTH_SECRET=|^DATABASE_URL="
|
||||
```
|
||||
|
||||
If you need worktree-specific overrides (different port, DB name, feature flags), create a `.env.local` alongside it - Next.js loads `.env.local` on top of `.env`.
|
||||
|
||||
Both must match. If either is missing, copy from a teammate or the main `.env.local`.
|
||||
|
||||
### 3. Install dependencies
|
||||
|
||||
```powershell
|
||||
Set-Location C:\dev\wwv\worldwideview.<branch-name>
|
||||
pnpm install
|
||||
```
|
||||
|
||||
### 4. Generate Prisma client
|
||||
|
||||
```powershell
|
||||
npx prisma generate
|
||||
```
|
||||
|
||||
### 5. (Optional) Sync with main
|
||||
|
||||
If the branch is behind main:
|
||||
|
||||
```powershell
|
||||
git merge main
|
||||
# or
|
||||
git rebase main
|
||||
```
|
||||
|
||||
### 6. Verify the dev server boots
|
||||
|
||||
```powershell
|
||||
pnpm dev
|
||||
```
|
||||
|
||||
Watch for the "Ready" line. If it fails, check:
|
||||
- Docker is running (needed for PostgreSQL): `docker compose up -d`
|
||||
- No port conflict on 3000: `netstat -ano | Select-String ":3000"`
|
||||
|
||||
### 7. Report ready
|
||||
|
||||
Once the dev server returns HTTP 200 on `http://localhost:3000`, the worktree is ready for use.
|
||||
|
||||
## .planning Branch Convention
|
||||
|
||||
Each feature worktree needs a matching branch in the `.planning` repo. The `SessionStart` and `post-checkout` hooks auto-switch `.planning` to that branch every time you open a session or switch branches in the worktree.
|
||||
|
||||
### When starting a new feature worktree
|
||||
|
||||
After Step 1 above, create the matching `.planning` branch (one-time per feature):
|
||||
|
||||
```powershell
|
||||
git -C C:\dev\wwv\.planning checkout -b <branch-name>
|
||||
git -C C:\dev\wwv\.planning push -u origin <branch-name>
|
||||
git -C C:\dev\wwv\.planning checkout main
|
||||
```
|
||||
|
||||
The `post-checkout` hook and `core.hooksPath` are applied automatically via `git init.templateDir` - no manual config step needed.
|
||||
|
||||
After this, every Claude Code session opened inside `worldwideview.<branch-name>` automatically switches `.planning` to `<branch-name>`. GSD agents see only that feature's phases.
|
||||
|
||||
Verify the sync is working after your first branch switch or session open:
|
||||
|
||||
```powershell
|
||||
git -C C:\dev\wwv\.planning rev-parse --abbrev-ref HEAD
|
||||
# Should output: <branch-name>
|
||||
```
|
||||
|
||||
### When finishing a feature
|
||||
|
||||
Merge the feature planning back to main before cleaning up the worktree:
|
||||
|
||||
```powershell
|
||||
git -C C:\dev\wwv\.planning checkout main
|
||||
git -C C:\dev\wwv\.planning merge <branch-name>
|
||||
git -C C:\dev\wwv\.planning push
|
||||
git -C C:\dev\wwv\.planning branch -d <branch-name>
|
||||
git -C C:\dev\wwv\.planning push origin --delete <branch-name>
|
||||
```
|
||||
|
||||
## Teardown
|
||||
|
||||
When done, remove the worktree cleanly (never `rm -rf` — orphans the Docker volume):
|
||||
|
||||
```powershell
|
||||
Set-Location C:\dev\wwv\worldwideview
|
||||
git-wt remove
|
||||
```
|
||||
@@ -29,20 +29,15 @@ A WorldWideView plugin is a self-contained data source that renders geospatial e
|
||||
|
||||
## Architecture Decision
|
||||
|
||||
```dot
|
||||
digraph plugin_type {
|
||||
rankdir=TB;
|
||||
node [shape=diamond];
|
||||
|
||||
"Does it need live\nexternal API data?" -> "Is polling\nfrequency > 30s?" [label="yes"];
|
||||
"Does it need live\nexternal API data?" -> "Static GeoJSON\n(wwvStaticCompiler)" [label="no"];
|
||||
"Is polling\nfrequency > 30s?" -> "Cron Seeder\n(engine)" [label="yes"];
|
||||
"Is polling\nfrequency > 30s?" -> "Init Seeder\n(engine)" [label="no"];
|
||||
|
||||
"Static GeoJSON\n(wwvStaticCompiler)" [shape=box];
|
||||
"Cron Seeder\n(engine)" [shape=box];
|
||||
"Init Seeder\n(engine)" [shape=box];
|
||||
}
|
||||
```
|
||||
Does it need live external API data?
|
||||
├── NO → Static GeoJSON plugin (wwvStaticCompiler in vite.config.ts)
|
||||
│ No seeder needed. Place data in data/data.json.
|
||||
└── YES → Does it update more often than every 30s?
|
||||
├── NO → Cron Seeder (engine, registerSeeder with cron string)
|
||||
│ getPollingInterval() = 0, mapWebsocketPayload() required
|
||||
└── YES → Init Seeder (engine, registerSeeder with init function)
|
||||
getPollingInterval() = 0, mapWebsocketPayload() required
|
||||
```
|
||||
|
||||
---
|
||||
@@ -146,7 +141,7 @@ export default class WildfiresPlugin implements WorldPlugin {
|
||||
| `getLayerConfig()` | Layer appearance (color, clustering, max entities) |
|
||||
| `renderEntity(entity)` | Per-entity Cesium rendering options |
|
||||
|
||||
**Optional:**
|
||||
**Optional (but `mapWebsocketPayload` is REQUIRED for WS-only plugins with object payloads):**
|
||||
|
||||
| Method | Purpose |
|
||||
|---|---|
|
||||
@@ -158,7 +153,7 @@ export default class WildfiresPlugin implements WorldPlugin {
|
||||
| `getDetailComponent()` | Custom detail panel for selected entity |
|
||||
| `getSettingsComponent()` | Plugin settings UI |
|
||||
| `getGlobeComponent()` | React component injected into globe view |
|
||||
| `mapWebsocketPayload(payload, existing)` | Transform raw WS data into `GeoEntity[]` |
|
||||
| `mapWebsocketPayload(payload, existing)` | **Required if seeder payload is an object** (not a flat array). Transforms raw engine payload → `GeoEntity[]`. Without it, `WsClient` drops object payloads silently. |
|
||||
| `requiresConfiguration(settings)` | Return `true` if plugin needs setup first |
|
||||
|
||||
### 1.3 Package Metadata
|
||||
@@ -518,14 +513,30 @@ export default class IssPlugin implements WorldPlugin {
|
||||
|
||||
destroy(): void {}
|
||||
|
||||
async fetch(timeRange: TimeRange): Promise<GeoEntity[]> {
|
||||
return []; // WS-only plugin
|
||||
async fetch(_timeRange: TimeRange): Promise<GeoEntity[]> {
|
||||
return []; // WS-only — data arrives via mapWebsocketPayload
|
||||
}
|
||||
|
||||
getPollingInterval(): number {
|
||||
return 0; // WS-only
|
||||
}
|
||||
|
||||
// REQUIRED: seeder sends { source, fetchedAt, items: [...], totalCount } (an object).
|
||||
// Without this, WsClient drops the payload silently — the globe stays empty.
|
||||
mapWebsocketPayload(payload: any, _existingEntities: GeoEntity[]): GeoEntity[] {
|
||||
const items: any[] = payload?.items ?? (Array.isArray(payload) ? payload : []);
|
||||
return items.map((item: any): GeoEntity => ({
|
||||
id: `iss-${item.id}`,
|
||||
pluginId: "iss",
|
||||
latitude: item.lat,
|
||||
longitude: item.lon,
|
||||
altitude: item.alt ?? 0,
|
||||
timestamp: new Date(),
|
||||
label: "International Space Station",
|
||||
properties: { speed: item.speed },
|
||||
}));
|
||||
}
|
||||
|
||||
getLayerConfig(): LayerConfig {
|
||||
return {
|
||||
color: "#ffffff",
|
||||
@@ -644,7 +655,9 @@ Categories are **lowercase**: `"aviation"` not `"Aviation"`, `"natural-disaster"
|
||||
- [ ] **Engine:** Seeder file in `wwv-seeders/src/seeders/<name>.ts` (or private repo)
|
||||
- [ ] **Engine:** `registerSeeder({ name })` matches frontend plugin `id`
|
||||
- [ ] **Engine:** Calls `setLiveSnapshot()` with correct plugin ID key
|
||||
- [ ] **Engine:** Data shape is an object with `items` array (or plugin implements `mapWebsocketPayload`)
|
||||
- [ ] **Engine:** Seeder payload is either a flat `GeoEntity[]` array OR plugin implements `mapWebsocketPayload` (any other object is silently dropped by WsClient)
|
||||
- [ ] **Frontend (WS-only):** `getPollingInterval()` returns `0` and `fetch()` returns `[]`
|
||||
- [ ] **Frontend (WS-only):** `mapWebsocketPayload(payload, existingEntities)` implemented if seeder sends an object
|
||||
- [ ] **Engine:** SQLite table created in `db.ts` if historical data needed
|
||||
- [ ] **Verification:** `GET localhost:5000/manifest` includes the plugin ID
|
||||
- [ ] **Verification:** `GET localhost:5000/health` shows seeder last-run timestamp
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
node_modules
|
||||
**/node_modules
|
||||
**/dist
|
||||
**/.next
|
||||
.git
|
||||
|
||||
# Database files at ANY depth
|
||||
/data
|
||||
packages/*/data
|
||||
**/*.db
|
||||
**/*.sqlite
|
||||
**/*.sqlite3
|
||||
**/*-journal
|
||||
**/*.db-wal
|
||||
**/*.db-shm
|
||||
|
||||
# ============================================================
|
||||
# UNIGNORE FOR AI AGENT (FILTERED PATHS ONLY)
|
||||
# ============================================================
|
||||
|
||||
# Code Frameworks, Configurations & Typings
|
||||
!/out/
|
||||
!*.tsbuildinfo
|
||||
!next-env.d.ts
|
||||
!/build
|
||||
!*.code-workspace
|
||||
|
||||
# Generated Codebase Assets & Database Schemas (e.g., Prisma Client)
|
||||
!/src/generated/
|
||||
|
||||
# Permanent Local Automation and Scripts Shared in Project
|
||||
!/local-scripts/
|
||||
!/public/plugins-local/
|
||||
|
||||
# Local Structural Repositories & Workspaces
|
||||
!local-plugins/*
|
||||
!/worldmonitor/
|
||||
!local-seeders/*
|
||||
|
||||
# Complete Ecosystem Repositories (Allows Agent to Cross-Reference Layouts)
|
||||
!/packages/wwv-data-engine/
|
||||
!/worldwideview-marketplace/
|
||||
!/worldwideview-plugins/
|
||||
!/worldwideview-web/
|
||||
!/wwv-data-engine/
|
||||
!/wwv-data-engine-public/
|
||||
!/wwv-seeders/
|
||||
!/wwv-seeders-private/
|
||||
!/wwv-test/
|
||||
!worldwideview.code-workspace
|
||||
+13
-1
@@ -2,7 +2,19 @@
|
||||
install_deps = "pnpm install"
|
||||
|
||||
[[pre-start]]
|
||||
copy_env = """powershell -Command "if (Test-Path '../worldwideview/.env') { Copy-Item '../worldwideview/.env' '.env' -Force }""""
|
||||
copy_env = """powershell -Command "if (Test-Path '../worldwideview/.env') { Copy-Item '../worldwideview/.env' '.env' -Force }; if (Test-Path '../worldwideview/.env.local') { Copy-Item '../worldwideview/.env.local' '.env.local' -Force }""""
|
||||
|
||||
[[pre-start]]
|
||||
copy_local_plugins = """powershell -Command "if (Test-Path '../worldwideview/local-plugins') { robocopy '../worldwideview/local-plugins' 'local-plugins' /E /XD node_modules dist .next coverage /XF '*.log' /NFL /NDL /NJH /NJS | Out-Null }; exit 0""""
|
||||
|
||||
[[pre-start]]
|
||||
copy_local_seeders = """powershell -Command "if (Test-Path '../worldwideview/local-seeders') { robocopy '../worldwideview/local-seeders' 'local-seeders' /E /XD .pnpm-store node_modules /NFL /NDL /NJH /NJS | Out-Null }; exit 0""""
|
||||
|
||||
[[pre-start]]
|
||||
link_planning = "powershell -File 'C:/dev/wwv/worldwideview/.agents/scripts/link-planning.ps1' '{{ worktree_path }}'"
|
||||
|
||||
[[pre-remove]]
|
||||
unlink_planning = "powershell -File 'C:/dev/wwv/worldwideview/.agents/scripts/unlink-planning.ps1' '{{ worktree_path }}'"
|
||||
|
||||
[[pre-remove]]
|
||||
docker_clean = "docker compose down -v"
|
||||
@@ -19,6 +19,12 @@ DATABASE_URL=postgresql://postgres:postgres@localhost:5432/worldwideview
|
||||
# at the project root so docker-compose can inject it.
|
||||
AUTH_SECRET=
|
||||
|
||||
# Encryption Master Key (REQUIRED — generate with: openssl rand -hex 16)
|
||||
# Must be exactly 32 characters. Used to derive the AES-256-GCM key for credentials at rest.
|
||||
# PRE-DEPLOY GATE: verify this is set in Coolify for every environment before merging C1 changes.
|
||||
# If unset the server will refuse to start (enforced in src/instrumentation.ts).
|
||||
ENCRYPTION_MASTER_KEY=
|
||||
|
||||
# Cesium Ion Access Token (optional — get one free at https://ion.cesium.com/)
|
||||
NEXT_PUBLIC_CESIUM_ION_TOKEN=
|
||||
|
||||
@@ -29,15 +35,34 @@ NEXT_PUBLIC_BING_MAPS_KEY=
|
||||
# Supabase Configuration (Optional — cloud-only features)
|
||||
# Found in your Supabase Project Settings > API
|
||||
NEXT_PUBLIC_SUPABASE_URL=
|
||||
# Preferred name for the Supabase anon/publishable key (matches worldwideview-marketplace).
|
||||
# NEXT_PUBLIC_SUPABASE_ANON_KEY is still accepted as a backwards-compat alias.
|
||||
NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY=
|
||||
NEXT_PUBLIC_SUPABASE_ANON_KEY=
|
||||
SUPABASE_SERVICE_ROLE_KEY=
|
||||
SUPABASE_DATABASE_URL=
|
||||
|
||||
# Cross-subdomain cookie domain (ADR-003).
|
||||
# Local dev with hosts-file trick: .wwv.local
|
||||
# Production: .worldwideview.dev
|
||||
# Leave empty when running on plain localhost (cookies cannot share across ports).
|
||||
NEXT_PUBLIC_WWV_COOKIE_DOMAIN=
|
||||
|
||||
# Auth host URL — the public URL of this WorldWideView instance when acting as auth host.
|
||||
# Used to build emailRedirectTo in signup and OAuth flows.
|
||||
# Local dev: http://wwv.local:3000
|
||||
# Production: https://worldwideview.dev
|
||||
NEXT_PUBLIC_AUTH_HOST_URL=
|
||||
|
||||
# OpenSky Network — multi-account credential rotation
|
||||
# Comma-separated clientId:clientSecret pairs.
|
||||
# Example: OPENSKY_CREDENTIALS=acct1-id:acct1-secret,acct2-id:acct2-secret
|
||||
OPENSKY_CREDENTIALS=
|
||||
|
||||
# OpenWeatherMap — Weather radar tile overlays (free tier: 1,000 calls/day)
|
||||
# Sign up at https://openweathermap.org/api and copy your API key.
|
||||
OPENWEATHERMAP_API_KEY=
|
||||
|
||||
# ACLED API — Civil Unrest & Conflict data (free for non-commercial use)
|
||||
# Register at https://developer.acleddata.com/ to obtain credentials.
|
||||
# Data is updated weekly (Mondays) with global protest, riot, and violence events.
|
||||
@@ -48,6 +73,25 @@ ACLED_PASSWORD=
|
||||
# Generate any random string, then set the same value in the marketplace instance config.
|
||||
WWV_BRIDGE_TOKEN=
|
||||
|
||||
# Marketplace URL — used by ticketClient.ts for token exchange (server-side only)
|
||||
# Falls back to NEXT_PUBLIC_WWV_MARKETPLACE_URL then https://app.worldwideview.dev
|
||||
MARKETPLACE_URL=
|
||||
|
||||
# Marketplace URL — used for PKCE connect/callback and client-side links
|
||||
NEXT_PUBLIC_WWV_MARKETPLACE_URL=
|
||||
|
||||
# Plugin Ticket Auth — comma-separated plugin IDs that require WS first-message auth (ADR-001).
|
||||
# Empty (default) = ticket auth dormant for all plugins. Set AFTER Marketplace + Data Engine deploy.
|
||||
# Example: NEXT_PUBLIC_WWV_TICKET_AUTH_PLUGINS=aviation,maritime
|
||||
NEXT_PUBLIC_WWV_TICKET_AUTH_PLUGINS=
|
||||
|
||||
# SSRF Proxy Host Allowlist (REQUIRED in production)
|
||||
# "*" = permissive (logs WARN per request — use to observe traffic for one week, then tighten).
|
||||
# "" = deny all (safe default when not set).
|
||||
# Comma-separated list = only those hostnames allowed (e.g. "192.168.1.100,camera.example.com").
|
||||
# Ship with "*" in Coolify; replace with concrete list after one week of log observation.
|
||||
PROXY_HOST_ALLOWLIST=*
|
||||
|
||||
# Default plugins enabled on boot for demo edition
|
||||
# Comma-separated list of plugin IDs
|
||||
NEXT_PUBLIC_DEMO_DEFAULT_PLUGINS=
|
||||
|
||||
Executable
+9
@@ -0,0 +1,9 @@
|
||||
#!/usr/bin/env bash
|
||||
# post-checkout hook: $1=prev HEAD, $2=new HEAD, $3=1 if branch checkout, 0 if file checkout
|
||||
# Only sync .planning on branch switches, not file restores.
|
||||
if [ "$3" = "1" ]; then
|
||||
SYNC_SCRIPT="C:/dev/wwv/.claude/hooks/planning-sync.sh"
|
||||
if [ -f "$SYNC_SCRIPT" ]; then
|
||||
bash "$SYNC_SCRIPT"
|
||||
fi
|
||||
fi
|
||||
@@ -0,0 +1,12 @@
|
||||
# Garbage Collector — Daily Sweep Prompt
|
||||
|
||||
You are the WorldWideView Garbage Collector agent running headless in GitHub Actions.
|
||||
|
||||
Run the garbage-collector agent sweep:
|
||||
|
||||
1. Read `.agents/rules/garbage-collection.md` for your charter and all guard rails.
|
||||
2. Read `gc-findings.json` for the pre-scanned findings produced by `scripts/gc-scan.mjs`.
|
||||
3. Check the `DRY_RUN` environment variable — if `true`, post a dry-run summary only (no PRs or Issues).
|
||||
4. Execute the full sweep procedure described in `.agents/agents/garbage-collector.md`.
|
||||
|
||||
Do not scan the codebase yourself. Work only from `gc-findings.json`.
|
||||
@@ -0,0 +1,116 @@
|
||||
name: Garbage Collector
|
||||
|
||||
on:
|
||||
schedule:
|
||||
- cron: '0 6 * * *' # 06:00 UTC daily
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
dry_run:
|
||||
description: 'Dry run — report findings only, open no PRs or Issues (recommended for first 3–5 days)'
|
||||
required: false
|
||||
default: 'true'
|
||||
type: choice
|
||||
options: ['true', 'false']
|
||||
days_branch:
|
||||
description: 'Days before a branch is considered stale'
|
||||
required: false
|
||||
default: '90'
|
||||
days_comment:
|
||||
description: 'Days before a TODO/FIXME comment is flagged'
|
||||
required: false
|
||||
default: '180'
|
||||
|
||||
concurrency:
|
||||
group: garbage-collector
|
||||
cancel-in-progress: true
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
pull-requests: write
|
||||
issues: write
|
||||
id-token: write
|
||||
|
||||
jobs:
|
||||
collect:
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 15
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GC_BOT_TOKEN }}
|
||||
DRY_RUN: ${{ github.event.inputs.dry_run || 'false' }}
|
||||
DAYS_BRANCH: ${{ github.event.inputs.days_branch || '90' }}
|
||||
DAYS_COMMENT: ${{ github.event.inputs.days_comment || '180' }}
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0 # full history required for git blame and branch age
|
||||
token: ${{ secrets.GC_BOT_TOKEN }} # PAT so pushed branches trigger CI
|
||||
|
||||
- name: Configure git user
|
||||
run: |
|
||||
git config user.name 'WorldWideView GC Bot'
|
||||
git config user.email '[email protected]'
|
||||
|
||||
- name: Setup pnpm
|
||||
uses: pnpm/action-setup@v4
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '22'
|
||||
cache: 'pnpm'
|
||||
|
||||
- name: Install dependencies
|
||||
run: pnpm install --frozen-lockfile
|
||||
|
||||
- name: Run deterministic scan
|
||||
run: |
|
||||
node scripts/gc-scan.mjs \
|
||||
--out gc-findings.json \
|
||||
--days-branch=${{ env.DAYS_BRANCH }} \
|
||||
--days-comment=${{ env.DAYS_COMMENT }}
|
||||
|
||||
- name: Upload findings artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: gc-findings-${{ github.run_id }}
|
||||
path: gc-findings.json
|
||||
retention-days: 30
|
||||
|
||||
- name: Run Garbage Collector agent
|
||||
uses: anthropics/claude-code-action@v1
|
||||
with:
|
||||
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
|
||||
show_full_output: true
|
||||
prompt: |
|
||||
You are the WorldWideView Garbage Collector agent running headless in GitHub Actions.
|
||||
|
||||
Read `.agents/rules/garbage-collection.md` for your charter and all guard rails.
|
||||
Read `gc-findings.json` for the pre-scanned findings produced by `scripts/gc-scan.mjs`.
|
||||
|
||||
The DRY_RUN environment variable is: ${{ env.DRY_RUN }}
|
||||
|
||||
## If DRY_RUN is "true":
|
||||
Do NOT create any PRs or Issues.
|
||||
Instead, find or create the tracking Issue titled "[gc-bot] Daily Scan Reports" (label: gc-bot) in
|
||||
the silvertakana/worldwideview repository using the gh CLI:
|
||||
|
||||
# Find existing tracking issue
|
||||
gh issue list --repo silvertakana/worldwideview --label gc-bot --search "[gc-bot] Daily Scan Reports" --json number,title
|
||||
|
||||
# If it exists, add a comment:
|
||||
gh issue comment <number> --repo silvertakana/worldwideview --body "..."
|
||||
|
||||
# If it doesn't exist, create it:
|
||||
gh issue create --repo silvertakana/worldwideview --title "[gc-bot] Daily Scan Reports" --label gc-bot --body "..."
|
||||
|
||||
The comment body must list every finding with: tier, file, line, description.
|
||||
Include the run ID (${{ github.run_id }}) and timestamp at the top.
|
||||
|
||||
## If DRY_RUN is "false":
|
||||
Execute the full sweep procedure described in `.claude/agents/garbage-collector.md`.
|
||||
Create Tier A draft PRs and Tier B Issues per the guard rails in `.agents/rules/garbage-collection.md`.
|
||||
|
||||
Do not scan the codebase yourself. Work only from gc-findings.json.
|
||||
claude_args: '--model claude-haiku-4-5-20251001 --allowedTools Bash,Read,Edit,Write,Grep,Glob'
|
||||
@@ -10,6 +10,10 @@ jobs:
|
||||
test:
|
||||
timeout-minutes: 60
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
browser: [chromium, firefox, webkit]
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
@@ -37,11 +41,16 @@ jobs:
|
||||
pnpm run predev
|
||||
|
||||
- name: Run Playwright tests
|
||||
run: pnpm test:e2e
|
||||
env:
|
||||
# Prevent Firefox from loading the AT-SPI/MSAA accessibility bridge on
|
||||
# Linux CI — without this, Firefox hangs for ~20 min waiting for a bus
|
||||
# that doesn't exist on ubuntu-latest runners.
|
||||
NO_AT_BRIDGE: ${{ matrix.browser == 'firefox' && '1' || '0' }}
|
||||
run: pnpm test:e2e --project=${{ matrix.browser }}
|
||||
|
||||
- uses: actions/upload-artifact@v4
|
||||
if: ${{ !cancelled() }}
|
||||
with:
|
||||
name: playwright-report
|
||||
name: playwright-report-${{ matrix.browser }}
|
||||
path: playwright-report/
|
||||
retention-days: 30
|
||||
@@ -13,6 +13,7 @@ jobs:
|
||||
env:
|
||||
NEXT_PUBLIC_WWV_EDITION: local
|
||||
AUTH_SECRET: ci-placeholder-secret-not-used-in-tests
|
||||
ENCRYPTION_MASTER_KEY: ci-placeholder-key-not-used-in-tests
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
|
||||
@@ -31,7 +32,10 @@ jobs:
|
||||
run: pnpm install --frozen-lockfile
|
||||
|
||||
- name: Setup environment
|
||||
run: cp .env.example .env
|
||||
run: |
|
||||
cp .env.example .env
|
||||
sed -i 's/^ENCRYPTION_MASTER_KEY=.*/ENCRYPTION_MASTER_KEY=ci-placeholder-key-not-used-in-tests/' .env
|
||||
sed -i 's/^AUTH_SECRET=.*/AUTH_SECRET=ci-placeholder-secret-not-used-in-tests/' .env
|
||||
|
||||
- name: Test predev setup
|
||||
# Tests that Docker DB boots, port mappings work, Prisma pushes schema, and plugins sync
|
||||
|
||||
+11
-5
@@ -19,12 +19,12 @@ node_modules/
|
||||
|
||||
# agents
|
||||
/.agents/plans
|
||||
/.agents/context
|
||||
/.agents/research/
|
||||
/.agents/context/
|
||||
/.agents/settings.local.json
|
||||
|
||||
# claude code IDE config
|
||||
/.claude/
|
||||
/.cline/
|
||||
# planning (private repo: github.com/silvertakana/wwv-planning)
|
||||
.planning/
|
||||
|
||||
# performance
|
||||
/performance/
|
||||
@@ -32,6 +32,9 @@ node_modules/
|
||||
# artifacts
|
||||
/artifacts/
|
||||
|
||||
# gc bot — generated scan output, never commit
|
||||
gc-findings.json
|
||||
|
||||
# scripts (tracked, but temporary scratchpads should go in /local-scripts/)
|
||||
|
||||
|
||||
@@ -64,7 +67,9 @@ yarn-error.log*
|
||||
.pnpm-debug.log*
|
||||
|
||||
# env files (can opt-in for committing if needed)
|
||||
.env*
|
||||
.env
|
||||
.env.local
|
||||
.env.test
|
||||
|
||||
# vercel
|
||||
.vercel
|
||||
@@ -96,6 +101,7 @@ packages/wwv-data-engine/
|
||||
|
||||
# IDE workspace files
|
||||
*.code-workspace
|
||||
*.vscode
|
||||
|
||||
# Build outputs and generated assets
|
||||
/public/cesium/
|
||||
|
||||
@@ -2,11 +2,8 @@
|
||||
|
||||
## 1. Project Identity
|
||||
|
||||
WorldWideView is a **real-time geospatial intelligence engine** that visualizes live global data on an interactive 3D globe. Built with **Next.js 16**, **CesiumJS**, **React 19**, and **Zustand**, it renders everything from live aircraft and maritime vessels to conflict events, satellites, and environmental data — all through a modular plugin architecture.
|
||||
WorldWideView is a **real-time geospatial intelligence engine** visualizing live global data on an interactive 3D globe. Built with **Next.js 16**, **CesiumJS**, **React 19**, and **Zustand**. Design/feature target: `www.worldmonitor.app` ([reference repo](https://github.com/koala73/worldmonitor)).
|
||||
|
||||
### Target Inspiration
|
||||
Our primary design, feature-set, and operational layout goal is to mimic the structure and capabilities of `www.worldmonitor.app`.
|
||||
- **Reference Codebase**: [GitHub - koala73/worldmonitor](https://github.com/koala73/worldmonitor)
|
||||
---
|
||||
|
||||
## 2. Tech Stack
|
||||
@@ -16,489 +13,153 @@ Our primary design, feature-set, and operational layout goal is to mimic the str
|
||||
| Framework | Next.js 16 (App Router, `output: "standalone"`) |
|
||||
| Language | TypeScript 5, strict mode |
|
||||
| 3D Engine | CesiumJS + Resium (Google Photorealistic 3D Tiles) |
|
||||
| State | Zustand (slice-based: globe, layers, timeline, UI, filters, data, config, favorites, geojson) |
|
||||
| State | Zustand (9 slices: globe, layers, timeline, ui, filter, data, config, favorites, geojson) |
|
||||
| Event Bus | Custom typed `DataBus` (pub/sub singleton) |
|
||||
| Styling | Vanilla CSS — **no Tailwind** |
|
||||
| Database | PostgreSQL via Prisma 7 (local and cloud) |
|
||||
| Database | PostgreSQL via Prisma 7 |
|
||||
| Auth | NextAuth v5 beta (Credentials provider, JWT sessions) |
|
||||
| Package Manager | pnpm (monorepo with `pnpm-workspace.yaml`) |
|
||||
| Testing | Vitest + jsdom + React Testing Library |
|
||||
| Deployment | Docker multi-stage build → Coolify |
|
||||
| Analytics | Vercel Analytics / custom `trackEvent` |
|
||||
|
||||
---
|
||||
|
||||
## 3. Directory Structure
|
||||
## 3. Critical Invariants
|
||||
|
||||
> [!NOTE]
|
||||
> See `.agents/rules/directory-structure.md` for the full project directory map and related repositories.
|
||||
|
||||
---
|
||||
|
||||
## 4. Architecture Patterns
|
||||
|
||||
> [!NOTE]
|
||||
> See [`docs/ARCHITECTURE.md`](docs/ARCHITECTURE.md) for the human-facing architecture deep-dive — plugin system, state management, data pipeline, data engine & seeders, rendering pipeline, and edition system.
|
||||
|
||||
Key invariants agents MUST respect:
|
||||
Agents MUST respect these at all times:
|
||||
|
||||
- **Plugin source of truth**: `@worldwideview/wwv-plugin-sdk` — never define plugin types locally.
|
||||
- **All-Bundle Model**: every plugin (seeder, CDN-loaded, static-compiled, active-proxied) is dynamically imported via `loadPluginFromManifest` using `import(/* webpackIgnore: true */ entry)`. Legacy `StaticDataPlugin` / `DeclarativePlugin` runtimes are deprecated.
|
||||
- **Agnostic frontend**: the renderer has no concept of a "unified" data engine. Each plugin **MUST declare its own `streamUrl`** in its manifest or config; do not assume one shared pipe.
|
||||
- **Nine Zustand slices** under `src/core/state/`: `globe`, `layers`, `timeline`, `ui`, `filter`, `data`, `config`, `favorites`, `geojson`. Access via `useStore` in React, `useStore.getState()` elsewhere.
|
||||
- **Primitive-based rendering** (not Cesium Entity API). Point/Billboard/Label/Polyline collections only. Never mix `size`/`outlineWidth`/`outlineColor` onto billboard entities — GPU silently clips.
|
||||
- **Three editions** controlled by `NEXT_PUBLIC_WWV_EDITION` (`local` / `cloud` / `demo`); feature flags derived in `src/core/edition.ts`.
|
||||
- **All-Bundle Model**: every plugin is dynamically imported via `loadPluginFromManifest` using `import(/* webpackIgnore: true */ entry)`. Legacy `StaticDataPlugin` / `DeclarativePlugin` runtimes are deprecated.
|
||||
- **Agnostic frontend**: each plugin **MUST declare its own `streamUrl`**; do not assume one shared pipe.
|
||||
- **Nine Zustand slices** under `src/core/state/`: access via `useStore` in React, `useStore.getState()` elsewhere.
|
||||
- **Primitive-based rendering**: Point/Billboard/Label/Polyline collections only. Never mix `size`/`outlineWidth`/`outlineColor` onto billboard entities — GPU silently clips.
|
||||
- **Three editions** via `NEXT_PUBLIC_WWV_EDITION` (`local` / `cloud` / `demo`); feature flags in `src/core/edition.ts`.
|
||||
- **Nested git clones**: `local-plugins/` (community plugins) and `local-seeders/community/` + `local-seeders/private/` (seeders) are **independent git repos cloned inside this repo, gitignored from it**. Each has its own remote. Run `git pull` inside each before editing; commits/pushes there go to their own upstream — not to `worldwideview`. See `.agents/context/ecosystem-repositories.md`.
|
||||
|
||||
---
|
||||
|
||||
## 5. Critical Conventions
|
||||
## 4. Conventions
|
||||
|
||||
### 5.1 File Size
|
||||
- **File size**: ~300 lines max. Extract helpers, split components, use hooks.
|
||||
- **Import aliases**: `@/*` → `./src/*`; `@worldwideview/wwv-plugin-sdk` → `./packages/wwv-plugin-sdk/src`
|
||||
- **CSS**: Vanilla CSS only. Global: `src/app/globals.css`. Scoped: CSS Modules. HUD: `src/styles/hud-animations.css`.
|
||||
- **Rendering entities**: Points use `type: "point"` + `size`/`outlineColor`/`outlineWidth`. Billboards use `type: "billboard"` + `iconUrl`/`iconScale`. NEVER mix.
|
||||
- **Plugin registration**: Built-ins via `AppShell.tsx` → `PluginRegistry` → `PluginManager`. Marketplace plugins via `InstalledPluginsLoader`.
|
||||
- **Workspace**: Use `"workspace:*"` (not `"*"`) for internal deps. New `packages/` plugins need `transpilePackages` in `next.config.ts`.
|
||||
- **Temp files**: Save debugging scripts/outputs exclusively in `/local-scripts/` — never in root.
|
||||
- **Cleanliness**: Remove dead code, unused imports, debug `console.log` before finalising. Never use `any` or `@ts-ignore`. Never create `.mdc` files.
|
||||
|
||||
**Guideline: ~300 lines per file.** If a file grows excessively large, consider modularizing it. Extract helpers, split components, or use hooks.
|
||||
---
|
||||
|
||||
### 5.2 Import Aliases
|
||||
|
||||
- `@/*` → `./src/*`
|
||||
- `@worldwideview/wwv-plugin-sdk` → `./packages/wwv-plugin-sdk/src`
|
||||
- Plugin modules are dynamically imported and do not require individual `tsconfig.json` aliases
|
||||
|
||||
### 5.3 CSS Rules
|
||||
|
||||
- **Vanilla CSS only** — no Tailwind, no CSS-in-JS
|
||||
- Global styles in `src/app/globals.css`
|
||||
- Component-scoped styles use CSS Modules (`.module.css`) or co-located `.css` files
|
||||
- HUD animations in `src/styles/hud-animations.css`
|
||||
|
||||
### 5.4 Rendering Entity Rules
|
||||
|
||||
When returning `CesiumEntityOptions` from `renderEntity()`:
|
||||
|
||||
- **Points**: Use `type: "point"` with `color`, `size`, `outlineColor`, `outlineWidth`
|
||||
- **Billboards**: Use `type: "billboard"` with `iconUrl`, `color`, `iconScale`
|
||||
- **NEVER mix**: Do not use `size`/`outlineWidth`/`outlineColor` on billboard entities — causes GPU clipping
|
||||
|
||||
### 5.5 Plugin Registration
|
||||
|
||||
Built-in plugins are instantiated in `AppShell.tsx` and registered via `PluginRegistry` → `PluginManager`. Marketplace-installed plugins are loaded from the database via `InstalledPluginsLoader`.
|
||||
|
||||
### 5.6 Workspace Rules
|
||||
|
||||
- Always run `pnpm install` from project root after creating new packages or linking local plugins
|
||||
- Official plugin packages go in `packages/wwv-plugin-<name>/`
|
||||
- Experimental/local plugin sandboxes go in `local-plugins/wwv-plugin-<name>/`
|
||||
- Globs for `packages/*`, `packages/*/backend`, and `local-plugins/*` are mapped in `pnpm-workspace.yaml` and `tsconfig.json` paths
|
||||
- Add new `packages/` plugins to `transpilePackages` in `next.config.ts` if required
|
||||
|
||||
### 5.7 AI Meta-Directives: Antigravity Standard
|
||||
|
||||
> [!NOTE]
|
||||
> This repository is orchestrated via the **Antigravity open standard**. The entry point for the agent framework is `CLAUDE.md` / `AGENTS.md` at the project root.
|
||||
## 5. AI Meta-Directives
|
||||
|
||||
> [!WARNING]
|
||||
> - **Always** use standard `.md` file extensions for rules, skills, and workflows.
|
||||
> - **Never** use proprietary `.mdc` extensions.
|
||||
> - **Never** reference Cursor IDE rules; we use the open `.agents/` standard.
|
||||
> - **MUST**: You MUST update Semantic Versioning numbering inside the relevant `package.json` file prior to executing any code commits, adhering strictly to the `[/commit]` workflow rules (`feat:` -> Minor, `fix/refactor/perf:` -> Patch).
|
||||
> - **MUST Detail Commit Levels & Bumps**: On description changes or release notes, you must detail the level of commit (Major/Minor/Fix) for *each* individual change. If there are multiple accumulated changes, you MUST EITHER commit them individually and bump the version each time, OR commit them all at once and bump the version multiple times.
|
||||
> - **MUST Explain Complex Concepts Simply**: Whenever providing a complicated technical explanation to the user, you MUST include a simple explanation below it. Use an analogy with reference to the correct terminology, comparing the concept to something from everyday life to ensure the user easily understands it.
|
||||
> - **MUST Be Transparent & Narrate Actions (Gemini 3.1 Agents)**: If you are a Gemini 3.1 agent, you MUST always be fully transparent. **Whenever you do anything, you must explicitly say what you are going to do in a visible chat message to the user, and ONLY THEN do it.** This ensures the user can actually see and verify what you are doing in real time. Do not jump to destructive actions without stating your intent first. Keep this narration conversational and natural. Avoid stiff, robotic templates. Just explicitly drop a brief, casual note about what you are checking, fixing, or deleting *before* you run the tool.
|
||||
> - **MUST Require Explicit Authorization**: Do NOT execute any state-changing tools (e.g., modifying files, writing code, running scripts, executing git commands) without first obtaining clear, explicit permission from the user to proceed with that specific action, **UNLESS** the action is a simple, straightforward, and safe operation (e.g., no deletion or dangerous operations). For safe operations, you may proceed without explicit permission. Otherwise, inform the user of your proposed plan and WAIT for their approval before acting. **Crucially, if you realize you have violated this rule by taking an unauthorized action, DO NOT automatically revert it. Reverting is itself an action that requires authorization. Just answer the question.**
|
||||
> - **MUST Ask Clarifying Questions**: Never assume anything. If requirements are unclear, if you encounter an unexpected roadblock, or if the user's intent could be interpreted in multiple ways, you MUST pause and ask clarifying questions. Do NOT proceed until the developer has explicitly answered your question or requested you to proceed anyway.
|
||||
|
||||
### 5.8 Workspace Hygiene
|
||||
Whenever agents generate temporary debugging scripts, test REST endpoints via `.mjs`, or dump traces/JSON outputs, they **MUST** save these exclusively inside `/local-scripts/`. The root directory is strictly for production configuration files.
|
||||
|
||||
### 5.9 Rule Adherence & Proactive Updates
|
||||
> [!CAUTION]
|
||||
> **Agents will trust the `.agents/rules/` files unconditionally.**
|
||||
> Whenever you execute a major architectural shift or make a change that invalidates an existing rule, you **MUST** immediately update the corresponding rule file(s) and/or `AGENTS.md` to reflect the new reality. Do not leave rules untouched after a change; operating on outdated information will cause future agents to break the codebase.
|
||||
> - Always use `.md` extensions. Never `.mdc`. Never reference Cursor IDE rules.
|
||||
> - **MUST** bump semver in `package.json` before every commit via `/commit` workflow (`feat:` → Minor, `fix/refactor/perf:` → Patch).
|
||||
> - **MUST** explain complex concepts simply — include an everyday-life analogy.
|
||||
> - **MUST** require explicit user authorization before any state-changing action that isn't simple/safe.
|
||||
> - **MUST** ask clarifying questions rather than assume when requirements are unclear.
|
||||
> - **MUST** update `.agents/rules/` files immediately whenever an architectural shift invalidates them.
|
||||
|
||||
---
|
||||
|
||||
## 6. Environment & Configuration
|
||||
|
||||
> [!NOTE]
|
||||
> See `.agents/rules/environment-config.md` for required environment variables and secrets.
|
||||
See `.agents/context/environment-config.md` for required environment variables and secrets.
|
||||
|
||||
---
|
||||
|
||||
## 7. Development, Deployment & Testing
|
||||
## 7. Development & Deployment
|
||||
|
||||
> [!NOTE]
|
||||
> See `.agents/rules/deployment-and-testing.md` for development commands, Docker architecture, Vitest strategy, and CSP security headers.
|
||||
```bash
|
||||
pnpm dev # Frontend only (auto-runs prisma db push + copy-cesium)
|
||||
pnpm dev:all # Frontend + data engine via Docker Compose
|
||||
pnpm build # Production build
|
||||
pnpm test # Vitest
|
||||
pnpm db:reset # Wipe + re-migrate DB (destructive)
|
||||
```
|
||||
|
||||
See `.agents/context/` → [deployment and testing details in `.agents/rules/deployment-and-testing.md`] for Docker architecture, Coolify rules, and CSP headers.
|
||||
|
||||
---
|
||||
|
||||
## 12. On-Demand Rules
|
||||
## 8. On-Demand Rules (path-scoped, auto-load on file access)
|
||||
|
||||
Read the relevant rule file when working in that domain:
|
||||
These load automatically when you read/edit files matching their paths:
|
||||
|
||||
| Rule | When to use | Path |
|
||||
|---|---|---|
|
||||
| `platform-architecture` | High-level platform goals, product vision, business model, and Edition System | `.agents/rules/platform-architecture.md` |
|
||||
| `application-architecture` | Next.js frontend, Zustand state management, and CesiumJS integration | `.agents/rules/application-architecture.md` |
|
||||
| `plugin-architecture` | Creating/modifying plugins, lifecycle, capability declarations, and seeders (See ADR-0001) | `.agents/rules/plugin-architecture.md` |
|
||||
| `marketplace-architecture` | Dynamic plugin installation, DB sync, CDN loading, and PKCE Auth (See ADR-0001) | `.agents/rules/marketplace-architecture.md` |
|
||||
| `cloud-auth-architecture` | Cloud edition, PostgreSQL RLS, multi-tenancy, and licensing | `.agents/rules/cloud-auth-architecture.md` |
|
||||
| `server-management` | Server development and debugging using SSH and Coolify MCP | `.agents/rules/server-management.md` |
|
||||
| `stakeholders-and-human-centered-design` | Human-centered design principles and stakeholder map | `.agents/rules/stakeholders-and-human-centered-design.md` |
|
||||
| `directory-structure` | Project structure and related repositories | `.agents/rules/directory-structure.md` |
|
||||
| `ecosystem-repositories` | WorldWideView ecosystem repositories and cross-repository workflows | `.agents/rules/ecosystem-repositories.md` |
|
||||
| `deployment-and-testing` | Docker build patterns, testing strategies, security headers | `.agents/rules/deployment-and-testing.md` |
|
||||
| `environment-config` | Secrets and environment variables | `.agents/rules/environment-config.md` |
|
||||
| `monorepo-workflow` | pnpm commands, adding packages, workspace config | `.agents/rules/monorepo-workflow.md` |
|
||||
| `data-engine-architecture` | Data Engine backend seeder loading, pnpm workspace dependencies | `.agents/rules/data-engine-architecture.md` |
|
||||
| `cesium-rendering` | Globe rendering, entity types, primitives, LOD, culling | `.agents/rules/cesium-rendering.md` |
|
||||
| `state-management` | Zustand slices, store access, plugin settings | `.agents/rules/state-management.md` |
|
||||
| `database-migrations` | Prisma schema changes, migrations, PostgreSQL | `.agents/rules/database-migrations.md` |
|
||||
| `continuous-improvement` | When to create/update rules, skills, or workflows | `.agents/rules/continuous-improvement.md` |
|
||||
| `context-and-memory` | How to orient and maintain project context between sessions | `.agents/rules/context-and-memory.md` |
|
||||
| `troubleshooting-and-debugging` | Resolving plugin latency, namespace collisions, or deployment issues | `.agents/rules/troubleshooting-and-debugging.md` |
|
||||
| `e2e-testing` | Guidelines and architecture for the Playwright End-to-End (E2E) testing infrastructure | `.agents/rules/e2e-testing.md` |
|
||||
| Rule | Triggers on |
|
||||
|---|---|
|
||||
| `.agents/rules/cesium-rendering.md` | `src/core/globe/**`, `src/plugins/**`, `packages/wwv-plugin-*/src/**` |
|
||||
| `.agents/rules/state-management.md` | `src/core/state/**`, `src/components/**` |
|
||||
| `.agents/rules/plugin-architecture.md` | `src/core/plugins/**`, `packages/wwv-plugin-*/src/**`, `local-plugins/**` |
|
||||
| `.agents/rules/marketplace-architecture.md` | `src/lib/marketplace/**`, `src/app/api/marketplace/**` |
|
||||
| `.agents/rules/cloud-auth-architecture.md` | `src/lib/auth*`, `src/app/api/auth/**`, `src/core/auth.ts` |
|
||||
| `.agents/rules/database-migrations.md` | `prisma/**` |
|
||||
| `.agents/rules/monorepo-workflow.md` | `packages/**`, `pnpm-workspace.yaml`, `local-plugins/**` |
|
||||
| `.agents/rules/data-engine-architecture.md` | `packages/**`, `local-seeders/**`, `docker-compose.yml` |
|
||||
| `.agents/rules/deployment-and-testing.md` | `Dockerfile`, `docker-compose.yml`, `.github/**`, `next.config.ts` |
|
||||
| `.agents/rules/e2e-testing.md` | `tests/**`, `public/e2e-fixtures/**`, `playwright.config.ts` |
|
||||
|
||||
---
|
||||
|
||||
## 13. Slash Commands / Workflows
|
||||
## 9. On-Demand Context (read explicitly when needed)
|
||||
|
||||
Invoke by name. Read the skill/workflow file and follow its steps.
|
||||
See `.agents/context/INDEX.md` for the full navigation table. Key files:
|
||||
|
||||
| When to read | File |
|
||||
|---|---|
|
||||
| Product vision, business model, Edition system | `.agents/context/platform-architecture.md` |
|
||||
| Finding files, repo layout | `.agents/context/directory-structure.md` |
|
||||
| Routing fix to correct repository | `.agents/context/ecosystem-repositories.md` |
|
||||
| Next.js, data pipeline, Redis, DB schema | `.agents/context/application-architecture.md` |
|
||||
| Debugging plugin data, namespace collisions | `.agents/context/troubleshooting-and-debugging.md` |
|
||||
| SSH, Coolify MCP | `.agents/context/server-management.md` |
|
||||
| Coding principles, Definition of Done | `.agents/context/coding-principles.md` |
|
||||
| `.env` variables and secrets | `.agents/context/environment-config.md` |
|
||||
|
||||
---
|
||||
|
||||
## 10. Slash Commands
|
||||
|
||||
| Command | Description | File |
|
||||
|---|---|---|
|
||||
| `/commit` | **Required before every commit** — bump semver + conventional commit | `.agents/skills/commit/SKILL.md` |
|
||||
| `/remember` | Save a lesson, constraint, or fact into `.agents/` permanent memory | `.agents/skills/remember/SKILL.md` |
|
||||
| `/remember` | Save a lesson or fact into permanent memory | `.agents/skills/remember/SKILL.md` |
|
||||
| `/pr-review` | 6-role comprehensive pull request review | `.agents/skills/pr-review/SKILL.md` |
|
||||
| `/update-context` | Sync `.agents/context/` with current project state | Global skill |
|
||||
| `/local-dev` | Check, start, and troubleshoot local dev environment | `.agents/workflows/local-dev.md` |
|
||||
| `/local-dev` | Check, start, troubleshoot local dev environment | `.agents/workflows/local-dev.md` |
|
||||
| `/data-engine-cli` | Use the wwv-data-engine CLI wrapper | `.agents/workflows/data-engine-cli.md` |
|
||||
| `/debugging-coolify` | Troubleshoot deployed apps on Coolify via MCP/SSH | `.agents/workflows/debugging-coolify.md` |
|
||||
| `/five` | Five Whys root cause analysis | `.agents/workflows/five.md` |
|
||||
| `/stitch-to-nextjs` | Generate UI with Stitch MCP, port into Next.js | `.agents/workflows/stitch-to-nextjs.md` |
|
||||
| `/bing-news-hydration` | Hydrate event attributes with Bing RSS news | `.agents/workflows/bing-news-hydration.md` |
|
||||
| `/generate-user-roadmap` | Generate updated user-facing roadmap | `.agents/workflows/generate-user-roadmap.md` |
|
||||
| `/branch-cleanup` | **Post-merge teardown** — commit leftovers, delete plan file, remove worktree via worktree-manager | `.agents/skills/branch-cleanup/SKILL.md` |
|
||||
|
||||
---
|
||||
|
||||
## 14. Agent Skills Reference
|
||||
|
||||
Refer to these skill documents for specialized tasks:
|
||||
|
||||
### Project Skills (`.agents/skills/`)
|
||||
## 11. Agent Skills Reference
|
||||
|
||||
| Skill | When to Use |
|
||||
|---|---|
|
||||
| `worldwideview-plugin-creation` | **Use when creating any plugin** — strict architectural checklist |
|
||||
| `plugin-creation-master-guide.md` | Decision matrix for choosing plugin architecture |
|
||||
| `osm-static-plugin-creation.md` | Creating static GeoJSON plugins from OpenStreetMap |
|
||||
| `microservice-plugin-creation.md` | Legacy guide for standalone Fastify microservices |
|
||||
| `database-operations.md` | Prisma schema changes, migrations, database queries |
|
||||
| `database-incident-recovery-procedures.md` | Authoritative protocol for safely restoring a broken production database |
|
||||
| `index-documentation.md` | Maintaining project documentation index |
|
||||
| `context7` | Fetch up-to-date library docs via Context7 API |
|
||||
| `cesium-context7` | CesiumJS-specific documentation lookup |
|
||||
| `database-incident-recovery-procedures.md` | Safely restoring a broken production database |
|
||||
|
||||
### Global Skills
|
||||
|
||||
52 skills are available across all projects. See `.agents/global-skills-index.md` for the full list and invocation paths.
|
||||
52 global skills available. See `.agents/global-skills-index.md`.
|
||||
|
||||
---
|
||||
|
||||
## 15. Pull Request & Commit Guidelines
|
||||
## 12. Pull Request & Commit Guidelines
|
||||
|
||||
- **Commit Format**: We strictly enforce Conventional Commits (`feat:`, `fix:`, `refactor:`, `perf:`).
|
||||
- **Workflow**: You **MUST** use the `/commit` workflow before every git commit to ensure proper semantic versioning bumps.
|
||||
- **Required Checks**: Ensure `pnpm test` and `pnpm build` complete successfully before proposing a merge.
|
||||
- **Review Process**: Use `/pr-review` to conduct a comprehensive multi-role review on any pull request.
|
||||
- **Git Worktrees & Database Lifecycle**: We use [Worktrunk](https://github.com/max-sixty/worktrunk) to manage parallel branches and avoid relative path breakage. `git-wt switch --create <branch>` provisions isolated sibling worktrees configured with `.env` files and `pnpm install`. The database port is assigned deterministically based on the directory hash.
|
||||
> [!CAUTION]
|
||||
> You MUST use `git-wt remove` to clean up worktrees. Manually deleting a worktree folder (`rm -rf`) will orphan the associated PostgreSQL Docker volume. If this happens, you must manually run `pnpm run db:prune` in the main repository to reclaim disk space.
|
||||
- **Commit format**: Conventional Commits (`feat:`, `fix:`, `refactor:`, `perf:`). Use `/commit` workflow.
|
||||
- **Required checks**: `pnpm test` and `pnpm build` must pass before merge.
|
||||
- **Review**: Use `/pr-review` for comprehensive multi-role review.
|
||||
- **Worktrees**: Use `git-wt switch --create <branch>` and `git-wt remove` (never `rm -rf` a worktree — orphans the PostgreSQL Docker volume). After a PR merges, use `/branch-cleanup` to commit leftovers, delete the plan file, and remove the worktree in one flow.
|
||||
|
||||
---
|
||||
|
||||
## 16. Debugging and Troubleshooting
|
||||
|
||||
- **Prisma & PostgreSQL Sync Issues**: If the local database state falls out of sync with Prisma schema, do not manually drop tables. Instead, run `pnpm db:reset` to cleanly wipe and re-apply all migrations.
|
||||
- **Cesium Entity Clipping**: If `billboard` entities are clipping or failing to render correctly, verify that you are not mixing `point` primitive properties (like `size` or `outlineWidth`) into the `billboard` options.
|
||||
- **Build Exhaustion (Docker)**: Multi-stage pnpm builds generate massive cache layers. If a Coolify deployment fails silently or PostgreSQL crashes abruptly, check host disk space and run `docker builder prune -a -f`.
|
||||
- **Next.js Typechecking Failures**: If backend-only `scripts/` fail during Next.js build, verify that the scripts directory is properly listed in the `exclude` array of `tsconfig.json`.
|
||||
|
||||
## 17. Coding Principles
|
||||
|
||||
You are about to write or modify code. **Read this file first.** It exists to prevent the failure mode where every fix makes the next harder — the kind of accumulated coupling and band-aid-on-band-aid that turns a clean codebase into a fragile one over months. This file is the constitution that keeps that from happening.
|
||||
|
||||
### The hard rule
|
||||
## Hard Rule
|
||||
|
||||
> **Always interface-based, extensible, composable, modular. Never band-aids on band-aids.**
|
||||
|
||||
If you find yourself adding a flag, an `if`-check, or a special case to make a problem go away, you are probably band-aiding. Stop and find the seam where the abstraction broke. Fix it there.
|
||||
|
||||
### Core principles
|
||||
|
||||
#### 1. Interfaces before implementations
|
||||
|
||||
Define the contract first. The contract is what other components depend on; the implementation is replaceable. Public functions accept the interface, not the concrete type.
|
||||
|
||||
```ts
|
||||
// Yes
|
||||
function attachSource(source: DataSource) { ... }
|
||||
|
||||
// No
|
||||
function attachPostgresSource(pg: PostgresInstance) { ... }
|
||||
```
|
||||
|
||||
When a pattern repeats across two modules, refactor it into an interface immediately. Don't wait for the third copy to "earn" the abstraction — by then the costs have compounded.
|
||||
|
||||
#### 2. Loose coupling through explicit contracts
|
||||
|
||||
Components communicate through well-defined contracts: typed function signatures, events on a bus, message queues, or capability registries. Pick the form that fits, but pick *one* and make it the only path.
|
||||
|
||||
Components do **not** communicate through:
|
||||
|
||||
- Direct imports of each other's internal modules
|
||||
- Shared mutable state outside the contract
|
||||
- Synchronous request/response when async fits the actual data flow
|
||||
- "Just this once" backdoors that bypass the contract
|
||||
|
||||
If you're tempted to write `import { internalThing } from '../other-module/internal'`, you are doing it wrong. If the symbol you need isn't part of the other module's public contract, either it should be — propose adding it — or you're solving the problem in the wrong place.
|
||||
|
||||
#### 3. Domain boundaries are sacred
|
||||
|
||||
Each domain (module, service, bounded context, plugin) owns its own state and its own surface. Cross-domain access is **explicit, gated, and audited** — never a shortcut.
|
||||
|
||||
Forbidden:
|
||||
- Reading another domain's storage directly
|
||||
- Calling another domain's private functions
|
||||
- Hardcoded `if (tenant === 'X')` or `if (mode === 'special')` branches in shared code
|
||||
|
||||
Allowed:
|
||||
- A documented capability or API on the other domain that you call
|
||||
- A configuration field on the relevant record that drives the strategy
|
||||
- Cross-domain access gated by explicit policy (default **deny**, opt-in per case), with the access itself logged
|
||||
|
||||
The rule of thumb: if removing a domain would require code archaeology in three other domains to figure out what depends on its internals, the boundary has already been violated. Treat that as a bug.
|
||||
|
||||
#### 4. Don't bend your architecture to fit a dependency
|
||||
|
||||
When you bring in a library or framework, use it where it fits cleanly; build natively where it doesn't.
|
||||
|
||||
Let the dependency handle (don't reinvent):
|
||||
- The thing it's specifically good at, in the shape it expects
|
||||
|
||||
Your code owns (the dependency can't represent):
|
||||
- Anything that's specifically your domain
|
||||
- Anything that requires identity, lifecycle, or invariants the dependency doesn't model
|
||||
- The integration seams between the dependency and your domain
|
||||
|
||||
If you find yourself bending your design to fit a library convenience, stop. Either the library has a hook for what you need, or you build it natively. Don't compromise architecture for the convenience of pulling in someone else's defaults.
|
||||
|
||||
#### 5. Data lifetimes are deliberate, not incidental
|
||||
|
||||
Different data has different lifetimes. Get this wrong and you'll either retain garbage forever or delete things users care about. Common categories:
|
||||
|
||||
- **Operational telemetry** (logs, metrics, internal events) — short rolling window. Useful for crash recovery and immediate investigation; not useful enough to keep forever.
|
||||
- **User content** (messages, documents, records the user created or that represent their lived experience with the system) — **permanent unless the user explicitly deletes it.** Never pruned by a sweep, never deleted by a retention policy authored for telemetry.
|
||||
- **Resumable session state** — bounded window appropriate to the use case; archived (state flag flipped) rather than deleted.
|
||||
|
||||
Name each category in your codebase. Write the retention policy for each one separately. Never propose a sweep that crosses categories — "delete events older than 30 days" is fine if events are telemetry; the same policy applied to user content is data loss masquerading as housekeeping. If storage pressure ever becomes real for content, introduce cold-tiered storage, not deletion.
|
||||
|
||||
#### 6. Optional features must be truly removable
|
||||
|
||||
Every optional feature (plugin, extension, integration, side module) declares its surface explicitly and communicates through the same contracts as everything else. No optional feature reaches into another's internals.
|
||||
|
||||
Test for whether something is core vs. optional: **if removing this feature should break the system, it's core. Otherwise it's optional, and it should be removable without leaving residue.**
|
||||
|
||||
If you can't delete an "optional" module's directory and have the system keep running, it isn't optional. Either fix the coupling or move it into core honestly.
|
||||
|
||||
#### 7. Put code where it belongs
|
||||
|
||||
When a feature spans layers (a trigger lives here, the action lives there, the data model lives somewhere else), resist the urge to fold it all into one place "for convenience." The feature lives in three places because each piece belongs to a different domain. Routing across them is the job — not collapsing them.
|
||||
|
||||
The general rule: if a feature needs to read/write durable state, it's a tool/extension on top of the layer that owns that state; if it's "the system should know about this concept," it's a configuration or contract change. Often it's both, with a thin handler that wires them together. That thin handler is fine — it's load-bearing — but it doesn't justify smashing the layers together.
|
||||
|
||||
### Antipatterns to refuse
|
||||
|
||||
These are common failure modes that, repeated over time, calcify a codebase. Refuse them when you catch yourself reaching for them.
|
||||
|
||||
| Antipattern | Better answer |
|
||||
|---|---|
|
||||
| Adding a new flag to an existing function instead of extracting a strategy | Extract the strategy interface; existing call sites pass the default strategy |
|
||||
| Patching around a bug at the call site | Find the seam where the abstraction broke; fix it there |
|
||||
| Direct database access from a feature module | Go through the layer that owns the data; if no surface exists, propose one |
|
||||
| Hardcoded paths, model names, IDs, environment specifics in business logic | Configuration; or look up via registry |
|
||||
| `if (tenant === 'X') { ... }` in shared code | Strategy on the record, or a per-tenant config field |
|
||||
| Inheriting one layer's concerns into another (or vice versa) | Cross the boundary through the documented contract |
|
||||
| "It works for now" — inline coupling between layers | If the layers are real, draw the contract; if they're not, merge them honestly |
|
||||
| Adding a defensive `try/catch` to swallow an error | Find why the error happens; gate cleanly at the right boundary |
|
||||
| Writing a comment to explain what code does | Rename and refactor so the code reads itself |
|
||||
| Copying a snippet from one module into another "to avoid the dependency" | Either it belongs in a shared module, or the duplicate will drift — pick |
|
||||
|
||||
### Debugging discipline
|
||||
|
||||
When something breaks:
|
||||
|
||||
1. **Reproduce it.** Don't trust intuition about what's failing.
|
||||
2. **Find the seam.** Where did the abstraction break? Which contract is being violated, and by whom?
|
||||
3. **Fix at the seam.** Not at the call site. Not at the consumer. At the boundary that's wrong.
|
||||
4. **If you can't find the seam, surface it.** Tell the user explicitly: "this is a design gap; the right fix needs an architectural decision, not a patch." Do not paper over.
|
||||
|
||||
If a fix doesn't work, **don't add another guard on top.** Find the real seam and gate cleanly. Stacked defensive layers are how clean codebases become unmaintainable.
|
||||
|
||||
### Lifecycle invariants and state-changing operations
|
||||
|
||||
Most recurring bugs cluster around the same shape: an operation crosses lifecycle state without checking, and the result is silent corruption, lost data, or orphan rows. The recipe that prevents recurrences:
|
||||
|
||||
1. **Name the invariant.** "Closed sessions don't accept work." "Scoped grants need a scope id." "Subscriptions past retention can't deliver swept events." Write it down before reaching for code.
|
||||
2. **Throw a typed error at the seam.** The single function that crosses the invariant refuses the bad case with a typed, named error — not a boolean return, not a silent skip, not a generic `Error`.
|
||||
3. **Pre-check at every call site that mutates *before* reaching the seam.** If the seam check fires after `store.append()`, you've left an orphan row. The pre-check is hygiene; the seam check is correctness — both are required. When the same pre-check appears at a second call site, extract a helper.
|
||||
4. **Validate, then mutate — never the reverse.** Within a single function, resolve all inputs that could fail (key derivation, lookups, permission checks) before touching durable state. A validation throw should leave nothing half-applied. If you can't separate validation from mutation, the function is doing two jobs.
|
||||
5. **A documented unsafe API is still unsafe.** A docstring that says "don't use this when X" is a foot-gun, not a warranty disclaimer. Either make the API safe in case X (drain, throw, refuse) or remove it.
|
||||
|
||||
If you're tempted to skip step 3 because "the seam check covers it," check whether the call site writes anything before reaching the seam. If yes, you need the pre-check.
|
||||
|
||||
### Definition of done — checklist for adding or updating a function
|
||||
|
||||
Every code change must satisfy the relevant checklist before merge. Refusal triggers below mean **stop and surface to the user** — do not ship a half-met checklist.
|
||||
|
||||
#### Adding a new function
|
||||
|
||||
All must be true:
|
||||
|
||||
- [ ] Belongs in this module (not somewhere else)
|
||||
- [ ] Fulfills an existing interface, OR a new interface is added with it (and reasons documented in a spec doc / ADR)
|
||||
- [ ] Has a doc-comment header (purpose + params + returns + thrown errors if relevant)
|
||||
- [ ] Has at least one test that targets the contract (not implementation details)
|
||||
- [ ] Test passes locally and in CI
|
||||
- [ ] Doesn't introduce direct cross-module imports of internals — communication through public contracts only
|
||||
- [ ] Doesn't touch storage owned by another component — route through that component's surface
|
||||
- [ ] Matches the spec doc's contract for this component (if no spec covers it, update the spec first)
|
||||
- [ ] Name is clear enough that the header comment is a summary, not an explanation
|
||||
|
||||
#### Updating an existing function
|
||||
|
||||
All must be true:
|
||||
|
||||
- [ ] Reason for change is clear (bug fix / new requirement / refactor / spec change)
|
||||
- [ ] Doc-comment still accurate after change (update if not)
|
||||
- [ ] Existing tests cover the new behavior (add new tests if not)
|
||||
- [ ] Build is green (all tests passing)
|
||||
- [ ] If this changes the contract: spec doc updated AND an ADR added if the change is load-bearing
|
||||
- [ ] Fix is at the seam, not at the symptom (no band-aid patches)
|
||||
- [ ] No new flags or special cases added in lieu of strategy extraction
|
||||
|
||||
#### Refusal triggers (any one means stop)
|
||||
|
||||
- Adding `if (tenant === 'X')` to shared code → use per-tenant config instead
|
||||
- Adding a flag to make a problem go away → extract the abstraction the flag implies
|
||||
- Direct DB or filesystem access from a feature module → route through the owning component
|
||||
- `try`/`catch` swallowing an error → find why the error happens, gate cleanly
|
||||
- Test omitted because "it's trivial" → no
|
||||
- Function-header skipped because "it's obvious" → no
|
||||
- "Just add another guard here" when a guard didn't work → find the real seam
|
||||
- Patch shipped to "unblock the build" without root-cause fix → no, surface the design gap
|
||||
|
||||
If any criterion isn't met, stop. Surface to the user as a design question. Don't paper over.
|
||||
|
||||
### Code-style minimums
|
||||
|
||||
#### Comments
|
||||
|
||||
**Every function gets a doc-comment header** in your language's idiomatic format (TSDoc, JSDoc, Python docstrings, Rust `///`, Javadoc, etc.). Not optional. Long-running codebases get re-read after gaps; function-header docs are how re-onboarding stays cheap.
|
||||
|
||||
Required content:
|
||||
|
||||
- One-line summary at a contract level (what the function guarantees, not what the code does line-by-line)
|
||||
- Each parameter and what it represents
|
||||
- Return value
|
||||
- Thrown errors / failure conditions if relevant
|
||||
- Example usage when the call shape is non-obvious
|
||||
|
||||
Apply this to public, internal, exported, and private functions. Apply to methods on classes too.
|
||||
|
||||
**Inline comments inside function bodies** still follow the standard rule: only for non-obvious WHY (hidden constraints, workarounds, surprising behavior, references to bug reports). Don't comment WHAT the code does — well-named identifiers and the function-header doc cover that.
|
||||
|
||||
#### Tests
|
||||
|
||||
**Every function ships with at least one test. Tests passing is a build requirement.**
|
||||
|
||||
- Tests target the contract (function signature + documented behavior + invariants), not implementation details. Refactoring should not break tests; behavior changes should.
|
||||
- A new implementation of an interface must pass the same contract test suite (write tests against the interface, not against a specific implementation).
|
||||
- Test names describe the case being verified, not the function: `it('refuses resume after archival window expires')` not `it('resumeSession')`.
|
||||
- For storage code: tests use a real (temporary) instance of the storage layer, created and torn down per test or per suite. Don't mock the storage engine — you're testing the wrong thing if you do.
|
||||
- For integration code that depends on an external library's hooks: contract tests against that library's surface so a dependency bump catches behavior changes.
|
||||
- Build pipeline (CI or local) runs all tests; non-zero exit = build fails. There is no "build succeeded but tests failed" state.
|
||||
|
||||
#### Logging
|
||||
|
||||
**Every new feature with a non-happy-path ships with a log line at each rare branch.** Use a structured logger with module-scoped child loggers. The log file is where "something's not working" turns into "what actually happened."
|
||||
|
||||
Level guidance:
|
||||
|
||||
- **info** — expected-but-noteworthy edges: a UI race that hits a closed resource, a permission bypass for a privileged principal. Correct behavior an operator might want to confirm fired.
|
||||
- **warn** — should be rare and worth investigating: race past a pre-check, lost events past retention, programmer/operator errors (calling a method after stop, a key that should have resolved didn't).
|
||||
- **error** — actual failures the operator must respond to: handler crashes, dispatch loop crashes, integration failures.
|
||||
- **debug** — high-volume internal state changes; always pair with a `module` field so it can be filtered.
|
||||
|
||||
Pass structured fields, not interpolated strings — fields are what makes a log queryable:
|
||||
|
||||
```ts
|
||||
// Yes
|
||||
logger.warn({ session_id, state }, "rejected append against non-live session");
|
||||
|
||||
// No
|
||||
logger.warn(`session ${session_id} (${state}) rejected append`);
|
||||
```
|
||||
|
||||
If you add a new typed error or a new event topic, also log it. The typed error tells the immediate caller; the event tells subscribers; the log tells the operator. The three are independent surfaces for the same fact, and all three are needed — events don't show up in the log, logs don't show up on the bus, errors don't survive the catch.
|
||||
|
||||
#### Structure
|
||||
|
||||
- Keep modules small. If a file is over ~500 lines, ask whether it has more than one responsibility.
|
||||
- Prefer explicit composition (caller wires things together) over implicit dependency-injection magic.
|
||||
- One public concept per module. If a file exports both `Foo` and `unrelatedHelperUsedNowhereElse`, the helper has the wrong home.
|
||||
|
||||
#### Dependencies
|
||||
|
||||
**Always check the registry for the current version before adding or updating a dependency.** Don't pick versions from memory.
|
||||
|
||||
The simple test: did you actually run `<package-manager> view <pkg> version` (or its equivalent) before pinning? If not, you're guessing — and the guess is almost always behind, sometimes by a major version with active deprecation.
|
||||
|
||||
Why this matters:
|
||||
|
||||
- **Long-running codebases.** Stale dependency anchors compound. A v3 you picked because that's what was on your mind will still be v3 a year later, and the v4 migration gets harder every month it waits.
|
||||
- **Active deprecations are real.** Common libraries are mid-deprecation cycles for older majors. Pinning to a soon-deprecated version on day one means the eventual upgrade is forced rather than chosen.
|
||||
- **"Latest" doesn't mean "use without thinking."** Read the changelog for breaking changes; decide whether to take them now or pin behind explicitly. But the *default* posture should be: pick latest, and justify in writing if pinning behind.
|
||||
|
||||
If you must pin behind latest, leave a comment in the manifest (or a CHANGELOG note) explaining why — a known incompatibility with another dep, an in-progress migration, a tested-and-rejected major bump. *"I haven't checked"* is not an acceptable reason.
|
||||
|
||||
Apply to: adding a new dep, updating an existing one, scaffolding a new package. *Not* required for routine no-op installs that don't touch versions.
|
||||
|
||||
#### Doc-vs-spec discipline
|
||||
|
||||
Specification documents (the deeper ones that describe how a component must behave) are **functional specifications**, not narrative essays. The discipline:
|
||||
|
||||
- **Concrete data structures** — type definitions, schemas, DDL, JSON examples
|
||||
- **Concrete function signatures** — input/output types, error types
|
||||
- **Concrete event/message payloads** — name + schema + example
|
||||
- **Concrete API signatures** — input/output schemas, side effects, permission requirements
|
||||
- **Flow pseudocode** — when orchestration is non-obvious
|
||||
- **Invariants** — explicitly listed: "after X happens, Y is always true"
|
||||
- **Failure modes** — enumerated: "if X fails, the system does Y"
|
||||
- **Acceptance tests** — statements another engineer can implement: "given input X, output Y"
|
||||
|
||||
Avoid in spec docs:
|
||||
- Long prose explaining motivation (that goes in ADRs / decision records)
|
||||
- Discussion of alternatives considered (also ADRs)
|
||||
- Background context (README handles this)
|
||||
- Marketing/aspirational tone
|
||||
|
||||
Spec docs are for implementation. Read one and you should know what to build.
|
||||
|
||||
### When in doubt
|
||||
|
||||
Ask the human user. Specifically:
|
||||
|
||||
- "I don't see a clean seam for this; the options I see are A or B. Which fits the architecture you have in mind?"
|
||||
- "This requires a new contract / capability / interface. Should I draft it before implementing?"
|
||||
- "I'm about to add a special case here; that smells like a missing abstraction. Do you want me to extract the abstraction or note the smell and defer?"
|
||||
|
||||
Don't ship band-aids and ask forgiveness later. The user has explicitly said: prevent that pattern.
|
||||
Read `.agents/context/coding-principles.md` before any non-trivial code change.
|
||||
+4
-1
@@ -21,6 +21,7 @@ services:
|
||||
required: false
|
||||
environment:
|
||||
- "AUTH_SECRET=${AUTH_SECRET:-default_secret_for_local_dev}"
|
||||
- "ENCRYPTION_MASTER_KEY=${ENCRYPTION_MASTER_KEY:-local_dev_encryption_key_change_in_prod}"
|
||||
- "WWV_DEMO_ADMIN_SECRET=${WWV_DEMO_ADMIN_SECRET:-}"
|
||||
- "WWV_BRIDGE_TOKEN=${WWV_BRIDGE_TOKEN:-}"
|
||||
- "DATABASE_URL=postgresql://postgres:postgres@db:5432/worldwideview?schema=public"
|
||||
@@ -58,11 +59,13 @@ services:
|
||||
command: >
|
||||
sh -c "
|
||||
echo 'Syncing workspace dependencies...' &&
|
||||
cd $$SEEDERS_DIR/community && CI=true pnpm install --ignore-scripts && pnpm -r rebuild better-sqlite3 esbuild &&
|
||||
if [ -d \"$$SEEDERS_DIR/community\" ]; then cd $$SEEDERS_DIR/community && CI=true pnpm install --ignore-scripts && pnpm -r rebuild better-sqlite3 esbuild; fi &&
|
||||
if [ -d \"$$SEEDERS_DIR/private\" ]; then cd $$SEEDERS_DIR/private && CI=true pnpm install --ignore-scripts && pnpm -r rebuild better-sqlite3 esbuild; fi &&
|
||||
cd /app && node dist/server.js"
|
||||
ports:
|
||||
- "5000:5000"
|
||||
volumes:
|
||||
- ./local-seeders:/app/seeders
|
||||
environment:
|
||||
- PORT=5000
|
||||
- REDIS_URL=redis://wwv-redis:6379
|
||||
|
||||
+54
-2
@@ -29,8 +29,60 @@ if [ -z "$DATABASE_URL" ]; then
|
||||
fi
|
||||
|
||||
echo "[entrypoint] Running database migrations..."
|
||||
prisma migrate deploy
|
||||
echo "[entrypoint] Migrations complete."
|
||||
set +e
|
||||
MIGRATE_OUT=$(prisma migrate deploy 2>&1)
|
||||
MIGRATE_CODE=$?
|
||||
set -e
|
||||
|
||||
if [ $MIGRATE_CODE -eq 0 ]; then
|
||||
echo "[entrypoint] Migrations complete."
|
||||
elif echo "$MIGRATE_OUT" | grep -q "P3005"; then
|
||||
# P3005: schema exists but _prisma_migrations has no history.
|
||||
# Happens when 'prisma db push' (pnpm dev) ran before 'prisma migrate deploy' (docker).
|
||||
# Safe to auto-baseline only if there is zero schema drift.
|
||||
echo "[entrypoint] P3005: schema exists without migration history."
|
||||
echo "[entrypoint] Verifying schema matches migrations before auto-baselining..."
|
||||
set +e
|
||||
DIFF_OUT=$(prisma migrate diff \
|
||||
--from-url "$DATABASE_URL" \
|
||||
--to-schema-datamodel prisma/schema.prisma \
|
||||
--script 2>&1)
|
||||
DIFF_CODE=$?
|
||||
set -e
|
||||
if [ $DIFF_CODE -ne 0 ]; then
|
||||
echo "[entrypoint] Could not verify schema state — aborting." >&2
|
||||
echo "$DIFF_OUT" >&2
|
||||
exit 1
|
||||
fi
|
||||
# Positive-match for DDL keywords: any real drift emits at least one of these.
|
||||
# Checking for presence is safer than checking for absence of content.
|
||||
if echo "$DIFF_OUT" | grep -qiE "^(CREATE|ALTER|DROP|INSERT|UPDATE|DELETE|TRUNCATE)"; then
|
||||
echo "[entrypoint] Schema drift detected — cannot auto-baseline." >&2
|
||||
echo "[entrypoint] Run 'pnpm db:reset' to wipe and re-migrate, or resolve drift manually." >&2
|
||||
echo "$MIGRATE_OUT" >&2
|
||||
exit 1
|
||||
fi
|
||||
echo "[entrypoint] No drift detected. Baselining existing schema..."
|
||||
for migration_dir in prisma/migrations/*/; do
|
||||
if [ -f "${migration_dir}migration.sql" ]; then
|
||||
migration_name=$(basename "$migration_dir")
|
||||
echo "[entrypoint] Marking as applied: $migration_name"
|
||||
set +e
|
||||
prisma migrate resolve --applied "$migration_name"
|
||||
RESOLVE_CODE=$?
|
||||
set -e
|
||||
if [ $RESOLVE_CODE -ne 0 ]; then
|
||||
echo "[entrypoint] Failed to baseline $migration_name — aborting." >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
done
|
||||
prisma migrate deploy
|
||||
echo "[entrypoint] Migrations complete."
|
||||
else
|
||||
echo "$MIGRATE_OUT" >&2
|
||||
exit $MIGRATE_CODE
|
||||
fi
|
||||
|
||||
# Generate self-signed SSL certificates for local HTTPS bridging if they don't exist
|
||||
if [ ! -f "./data/localhost.crt" ] || [ ! -f "./data/localhost.key" ]; then
|
||||
|
||||
+6
-4
@@ -75,9 +75,11 @@ For legacy plugins (e.g., Webcams) that *cannot* use WebSockets, the local proxy
|
||||
## Operational Implementation Details
|
||||
|
||||
### 1. Library Selection
|
||||
* **`jose`:** The industry-standard library for modern JS. Used by the Marketplace to generate Ed25519 keys, sign JWTs, and expose the JWKS endpoint.
|
||||
* **`jose`:** The industry-standard library for modern JS. Used by the Marketplace to generate Ed25519 keys, sign JWTs, and expose the JWKS endpoint. **Also used by Data Engines** to verify tickets — `createRemoteJWKSet` handles remote fetching, caching, and `kid` selection, and `jwtVerify` validates the signature plus `iss`/`aud`/`exp` in one call, with native OKP/Ed25519 support.
|
||||
* **`openid-client`:** The RFC-compliant library used by the Local App to execute the PKCE Authorization Code flow securely.
|
||||
* **`@fastify/jwt` + `get-jwks`:** Used by Data Engines. `@fastify/jwt` provides the middleware, while `get-jwks` (built by the Fastify core team) handles remote fetching, local LRU caching, and OKP-to-PEM conversion for Ed25519 keys.
|
||||
|
||||
> [!NOTE]
|
||||
> **Amendment (2026-05-22):** The original draft specified `@fastify/jwt` + `get-jwks` for Data Engines. This was found to be incorrect during local integration testing: `get-jwks.getPublicKey()` converts JWKs via `jwk-to-pem`, which **does not support OKP/Ed25519 keys** (throws `Unsupported key type "OKP"`). `@fastify/jwt`'s standalone `verify()` is also incompatible with a remote-JWKS async key resolver. Data Engines now use `jose` — the same library already mandated for the Marketplace — which supports Ed25519 natively.
|
||||
|
||||
### 2. Hardened First-Message Auth
|
||||
Data Engines MUST enforce strict WebSocket handshake rules:
|
||||
@@ -145,8 +147,8 @@ sequenceDiagram
|
||||
M->>L: 5-min JWT (aud: Engine A)
|
||||
L->>U: JWT
|
||||
U->>E: wss://engine (Origin validation)
|
||||
U->>E: { type: "auth", jwt: "..." }
|
||||
E->>E: Verify with get-jwks cache
|
||||
U->>E: { type: "auth", v: 1, token: "..." }
|
||||
E->>E: Verify JWT via jose (cached JWKS)
|
||||
E->>U: Stream
|
||||
end
|
||||
```
|
||||
@@ -0,0 +1,158 @@
|
||||
# ADR-0002: Source-of-truth for plugin identity and registration
|
||||
|
||||
## Status
|
||||
Accepted
|
||||
|
||||
## Date
|
||||
2026-05-20
|
||||
|
||||
## Context
|
||||
|
||||
Two related problems in the plugin system surfaced in the same period, and both have the same root cause: canonical plugin information was being derived in middleware translation layers (folder names, hard-coded lists) rather than at its proper source. Each problem is fixed by pushing the canonical truth back to its rightful owner and removing the static translation in the middle. Documenting them together makes the shared principle explicit and discourages future regressions of the same shape.
|
||||
|
||||
### Problem 1 — Engine seeder ID derived from folder name
|
||||
|
||||
The WorldWideView local data engine discovers seeders by scanning the filesystem under `/app/seeders`. Historically, the engine assigned each seeder an ID equal to its **folder name** (e.g., the folder `gpsjam/` became plugin ID `"gpsjam"`).
|
||||
|
||||
The frontend, however, identifies plugins by a separate **`id` field** declared in each plugin class (e.g., `"gps-jamming"`). The engine's `/manifest` endpoint listed available plugins using folder-derived IDs, and the frontend's `localEngineHasPlugin(pluginId)` performed an exact string match against that list.
|
||||
|
||||
This created a silent failure mode: six seeders had folder names that did not match their corresponding frontend plugin IDs:
|
||||
|
||||
| Folder name | Frontend plugin `id` |
|
||||
|---|---|
|
||||
| `gpsjam/` | `gps-jamming` |
|
||||
| `sanctions/` | `international-sanctions` |
|
||||
| `wildfires/` | `wildfire` |
|
||||
| `civilUnrest/` | `civil-unrest` |
|
||||
| `conflictEvents/` | `conflict-events` |
|
||||
| `cyberAttacks/` | `cyber-attacks` |
|
||||
|
||||
When `localEngineHasPlugin('gps-jamming')` returned `false` (because the manifest listed `"gpsjam"`), the frontend silently fell through to the production cloud engine, bypassing the local engine entirely. The bug was invisible — no error, just incorrect routing.
|
||||
|
||||
A short-term patch introduced `SEEDER_ID_ALIASES` in `src/core/data/engineManifest.ts` — a frontend translation map from folder names to plugin IDs. This was explicitly a band-aid: it duplicated knowledge in a consumer rather than fixing the contract at the source, and would go stale as new seeders were added.
|
||||
|
||||
The engine's TypeScript source (`seeder-loader.ts`) also had a `toKebabCase()` helper intended to normalize camelCase folder names (e.g., `civilUnrest` → `civil-unrest`), but its compiled `dist/` was stale (the production image had not been rebuilt to include it), and `toKebabCase` alone cannot resolve abbreviation mismatches like `gpsjam` → `gps-jamming`.
|
||||
|
||||
### Problem 2 — Fresh-install plugin set hard-coded
|
||||
|
||||
The marketplace auto-seeder ([src/lib/marketplace/seedDefaultPlugins.ts](../../../src/lib/marketplace/seedDefaultPlugins.ts)) writes a starter set of plugins to the database on first boot so the globe isn't empty on day one. The list of plugins to seed lived in a hard-coded constant `DEFAULT_PLUGIN_IDS` ([src/lib/marketplace/defaultPlugins.ts](../../../src/lib/marketplace/defaultPlugins.ts)).
|
||||
|
||||
Two failure modes followed from the static list:
|
||||
|
||||
1. **Drift**: ten plugins were published to npm under `@worldwideview/*` and verified — surveillance-satellites, military-bases, embassies, seaports, lighthouses, spaceports, iranwarlive, undersea-cables, mineral-mines, nuclear-facilities — but never added to `DEFAULT_PLUGIN_IDS`. Fresh installs missed them silently.
|
||||
2. **Phantom 404s**: two entries in the list (`fortiguard`, `nz-traffic-cameras`) were dev-only sandboxes in `local-plugins/`, never published to npm. Every fresh boot hit `https://marketplace.worldwideview.dev/api/plugins/fortiguard` → 404, logged a warning, and continued. The branch `fix/diagnose-plugins-404` was opened to diagnose those.
|
||||
|
||||
A separate, signed verified-plugins registry already existed at `marketplace.worldwideview.dev/api/registry`, loaded by [registryClient.ts](../../../src/lib/marketplace/registryClient.ts) with Ed25519 verification. It was used for trust-stamping installed plugins but not for selecting which plugins to seed. That registry is the authoritative list of plugins that have been reviewed and verified — exactly the list a starter set should come from.
|
||||
|
||||
### Shared shape
|
||||
|
||||
Both problems wrap the same anti-pattern: a consumer (frontend, seeder) maintains a static translation/list derived from the producer's actual identity (seeder export, npm publication). The translation drifts. The fix in both cases is the same: stop translating in the consumer; let the producer declare the truth and consume it directly.
|
||||
|
||||
## Decisions
|
||||
|
||||
### Decision 1 — The seeder's exported `name` field is the canonical plugin ID
|
||||
|
||||
The engine reads each seeder's `dist/index.mjs` default export's `name` property and uses it as the plugin ID everywhere:
|
||||
|
||||
- `/manifest` endpoint `plugins` array
|
||||
- WebSocket welcome message plugin list
|
||||
- WebSocket data message `pluginId` field
|
||||
- Redis key (`data:<name>:live`)
|
||||
- Scheduler logs
|
||||
|
||||
The folder name is used only as a filesystem fallback if the seeder exports no `name`. The engine logs a warning at startup whenever the kebab-cased folder name differs from the seeder's exported `name`, making drift visible without blocking startup.
|
||||
|
||||
**Contract:** Every seeder MUST export a `name` field that exactly equals the corresponding frontend plugin's `id` field (kebab-case). This is a two-place contract: declare the same ID string in the seeder export and in the frontend plugin class.
|
||||
|
||||
Implementation: `seeder-loader.ts` was updated to set `id = seederConfig.name || toKebabCase(folderName)` instead of `id = toKebabCase(folderName)`. The frontend `SEEDER_ID_ALIASES` map was removed entirely. No translation layer exists between the engine's manifest and the frontend's plugin lookup.
|
||||
|
||||
### Decision 2 — The signed verified registry is the source-of-truth for fresh-install auto-seeding
|
||||
|
||||
The marketplace auto-seeder iterates the set returned by `getVerifiedPluginIds()` (the signed registry) instead of a hard-coded `DEFAULT_PLUGIN_IDS` constant. Publishing a plugin to the verified registry automatically makes it part of the fresh-install starter set on subsequent boots, with no code change.
|
||||
|
||||
The static `DEFAULT_PLUGIN_IDS` list is deleted. There is no fallback list in code — if the registry is unreachable on first attempt, the seeder defers without marking-seeded so the next request retries (the 5-min in-memory cache in `registryClient.ts` bounds the request rate during outages).
|
||||
|
||||
Trust stamping is collapsed: every plugin landed by the seeder is `verified` by definition, so the per-plugin `verified.has(pluginId)` check inside the seeder is dropped — `manifest.trust = "verified"` is set directly.
|
||||
|
||||
**Contract:** A plugin is part of the fresh-install starter set iff it appears in the signed verified-plugins registry. There is no other list to maintain.
|
||||
|
||||
## Shared principle
|
||||
|
||||
> **Canonical plugin truth lives at the source. Reject static translation/lookup layers in the middle.**
|
||||
|
||||
This is the architectural rule both decisions encode. Concrete corollaries for future contributions:
|
||||
|
||||
- Don't introduce a static map in a consumer to compensate for a producer that mis-labels itself. Fix the producer.
|
||||
- Don't introduce a static list in code to enumerate what a registry or filesystem already enumerates. Read from the registry/filesystem.
|
||||
- A translation layer that "just needs an entry added each time we publish a plugin" is a foot-gun — it will silently drift the moment someone forgets.
|
||||
|
||||
## Alternatives Considered
|
||||
|
||||
### For Decision 1
|
||||
|
||||
#### Folder renames (rejected as primary fix)
|
||||
Rename the six mismatched folders to match their frontend plugin IDs (e.g., `gpsjam/` → `gps-jamming/`). This would make the folder name the canonical ID.
|
||||
|
||||
- **Rejected as primary fix** because Windows Docker Desktop holds NTFS volume mount locks on running containers, making renames impossible without a full Docker Desktop shutdown. More importantly, it makes the canonical ID fragile — any accidental folder rename breaks routing silently.
|
||||
- Folder renames remain a cosmetic cleanup option, now that the seeder export is the actual source of truth.
|
||||
|
||||
#### Frontend alias map (`SEEDER_ID_ALIASES`)
|
||||
Maintain a static mapping in `engineManifest.ts` that translates engine-reported IDs to frontend plugin IDs.
|
||||
|
||||
- **Rejected** because it puts translation responsibility on the consumer rather than the producer. Every new seeder with a naming mismatch requires a manual alias entry. The map goes stale silently — no warning if an alias is wrong or missing.
|
||||
|
||||
#### `toKebabCase()` normalization only
|
||||
Apply `toKebabCase()` to folder names in the engine and rely on the convention that folder names encode the plugin ID in camelCase.
|
||||
|
||||
- **Rejected** because `toKebabCase` cannot resolve abbreviation mismatches (`gpsjam` → still `gpsjam`, not `gps-jamming`) or singular/plural differences (`wildfires` → still `wildfires`, not `wildfire`). It only handles camelCase-to-kebab conversion.
|
||||
|
||||
#### Strict validation with engine startup failure
|
||||
Refuse to load any seeder whose folder name doesn't match its exported `name`, blocking startup until inconsistencies are resolved.
|
||||
|
||||
- **Rejected** as too aggressive for a local dev environment. A warning is sufficient — startup continues, mismatches are visible, and the system keeps working.
|
||||
|
||||
### For Decision 2
|
||||
|
||||
#### Add the missing 10 IDs to `DEFAULT_PLUGIN_IDS` (rejected)
|
||||
Extend the static list to include the newly-published plugins.
|
||||
|
||||
- **Rejected** because it ships a fix that resolves the immediate symptom while preserving the underlying drift mechanism. The list would go stale again the next time a plugin is published.
|
||||
|
||||
#### Hybrid: registry as default + static fallback list
|
||||
Read from the registry; fall back to a hard-coded list if the registry is empty/unreachable.
|
||||
|
||||
- **Rejected** because it reintroduces the static list as a permanent shadow source-of-truth. Fallback lists go stale silently. The chosen "defer seeding on empty registry" behavior is safer — fresh installs retry on the next request rather than locking in a stale set.
|
||||
|
||||
#### Delete auto-seeding entirely (rejected)
|
||||
Drop the seeder and let users install everything from the marketplace UI starting from an empty globe.
|
||||
|
||||
- **Rejected** because fresh installs should have something to look at on day one. The user explicitly stated this requirement: "we want the user to have something to get started with."
|
||||
|
||||
## Consequences
|
||||
|
||||
### Easier
|
||||
|
||||
**Decision 1 — engine seeder identity**
|
||||
- Self-documenting identity. Reading any seeder's `src/index.ts` immediately tells you its plugin ID. No external registry to consult.
|
||||
- Filesystem layout is irrelevant. Folders can be named for readability or organized in subdirectories without affecting routing.
|
||||
- No translation layers. The frontend receives the correct ID directly from the manifest; `localEngineHasPlugin()` works with a direct string comparison.
|
||||
- Drift is visible. The engine warns on startup when folder names diverge from exported names, catching mistakes during development rather than silently at runtime.
|
||||
- Adding a new seeder requires only: (1) export `name: '<plugin-id>'` matching the frontend plugin's `id`, (2) no registration step, no alias map entry.
|
||||
|
||||
**Decision 2 — marketplace seeding**
|
||||
- Publishing a plugin to the verified registry is sufficient to add it to the starter set. No code change, no PR to add an ID to a constant.
|
||||
- Phantom 404s are gone. The seeder only queries IDs that exist in the verified registry, which by construction reflects what's actually published.
|
||||
- Trust semantics align. "Verified" and "auto-seeded on fresh install" are now the same condition, not two near-overlapping lists that can drift.
|
||||
- Registry outages no longer brick fresh installs. The deferral semantics ensure the seeder retries instead of marking-seeded with zero rows.
|
||||
|
||||
### Harder
|
||||
|
||||
**Decision 1 — engine seeder identity**
|
||||
- Seeder author bears responsibility. If a seeder exports the wrong `name`, routing fails silently (same failure mode as before, but now localized to the seeder rather than the folder). The startup warning mitigates this.
|
||||
- Contract validation is advisory, not enforced. There is no build-time check that the seeder's `name` matches an actual frontend plugin `id`. A validation script (`scripts/validate-seeder-ids.mjs`) is the recommended mitigation.
|
||||
- Engine image must be kept up to date. The fix lives in `dist/seeder-loader.js` inside the Docker image. If the published `ghcr.io/silvertakana/wwv-data-engine:latest` image is behind the local source, the behavior reverts to folder-name-based IDs. Local changes require `docker cp` injection or an image rebuild until the fix is published.
|
||||
|
||||
**Decision 2 — marketplace seeding**
|
||||
- The verified registry must be kept accurate. A newly-published plugin doesn't auto-seed until it's added to the registry and the registry is re-signed. Operational responsibility shifts from "remember to add the ID to a code constant" to "remember to add the ID to the registry" — a similar discipline, but now at the right layer (the marketplace, not the consumer).
|
||||
- Existing instances are not back-filled. Users whose `Setting` table already has `defaults_seeded=true` will not automatically receive newly-verified plugins; they must install via the marketplace UI. This is by design — re-seeding could reinstall plugins a user explicitly uninstalled.
|
||||
- Dev-only sandboxes (`local-plugins/<name>/`) no longer "tag along" via the default list. `fortiguard` and `nz-traffic-cameras` only reach users once published to npm and added to the verified registry. The local-plugins folder discovery in `/api/marketplace/load` still surfaces them in dev (`NODE_ENV=development` or `WWV_PLUGIN_DEV=true`).
|
||||
@@ -0,0 +1,188 @@
|
||||
# ADR-0003: Shared Identity & Ecosystem Authentication Host
|
||||
|
||||
## Status
|
||||
Accepted *(Phase 2A-D implementation complete 2026-05-25)*
|
||||
|
||||
### Implementation notes (Phase 2 closeout)
|
||||
- `worldwideview/src/lib/supabase/cookieOptions.ts`, `server.ts`, `client.ts` added — mirrors marketplace recipe
|
||||
- `worldwideview/src/app/login/actions.ts` migrated from `@supabase/supabase-js` to `@supabase/ssr` `createServerClient` so login actually persists a Supabase session cookie
|
||||
- `getSafeRedirect` updated to allow trusted subdomains via `NEXT_PUBLIC_WWV_COOKIE_DOMAIN`
|
||||
- `/auth/callback` route added to handle Supabase PKCE email verification flow
|
||||
- `/signup` page and server action added at the auth host
|
||||
- `worldwideview-marketplace/src/app/api/install/start/route.ts` — new server-side auth gate for plugin installs
|
||||
- `InstallButton.handleInstall` retargeted to `/api/install/start` (was building WWV URL client-side with no auth check)
|
||||
- `requireSupabaseUser` redirect param renamed `?next=` to `?callbackUrl=` to match WWV login page
|
||||
- `install-redirect/route.ts` updated to use Supabase auth for cloud edition, NextAuth for local/demo
|
||||
- `httpOnly: true` added to `buildCookieOptions()` in both repos
|
||||
- NextAuth (Credentials provider) retained for local and demo editions
|
||||
|
||||
## Date
|
||||
2026-05-22
|
||||
|
||||
## Related
|
||||
- **Builds on:** ADR-001 (Decentralized Plugin Auth & SSRF Mitigation) — specifically the PKCE flow that lets the Local App acquire tokens from the Marketplace
|
||||
- **Supersedes:** `.agents/rules/cloud-auth-architecture.md` (which incorrectly states that `app.worldwideview.dev` owns all login UI — this ADR reverses that)
|
||||
|
||||
---
|
||||
|
||||
## Context
|
||||
|
||||
WorldWideView is growing into a multi-product ecosystem:
|
||||
|
||||
| Product | URL | Purpose |
|
||||
|---|---|---|
|
||||
| Landing / Auth | `worldwideview.dev` | Marketing, login, signup, cloud plan registration |
|
||||
| Marketplace | `marketplace.worldwideview.dev` | Browse, install, and manage plugins |
|
||||
| Cloud App | `app.worldwideview.dev` (or `[tenant].app.worldwideview.dev`) | Hosted geospatial intelligence instance |
|
||||
| Local App | Self-hosted | User's own instance, authenticated locally |
|
||||
|
||||
Four interrelated problems required a unified decision:
|
||||
|
||||
1. **No Marketplace identity system exists.** Users have nowhere to create an account, log in, or manage subscriptions.
|
||||
2. **Fragmented account experience.** Without a plan, a user would need separate accounts for the Marketplace and the Cloud App — unacceptable for a single-vendor ecosystem.
|
||||
3. **Cookie domain fragmentation.** If each product hosts its own login page, sessions cannot be shared across subdomains. A user logged into the Marketplace would need to log in again at the Cloud App.
|
||||
4. **The `worldwideview-web` repo is a static export** (`output: "export"`). It has a `/login` page backed by client-side Supabase but cannot support server-side sessions, API routes, or cross-subdomain cookie management.
|
||||
|
||||
---
|
||||
|
||||
## Decisions
|
||||
|
||||
### ADR-003A: Federated Identity — One Account Across All Products
|
||||
|
||||
All WorldWideView products share a **single identity**. A user who creates an account anywhere in the ecosystem (Marketplace, Cloud App, or the landing site) has that same identity available everywhere else.
|
||||
|
||||
This is the standard industry pattern for multi-product SaaS — used by GitHub (one account → GitHub, Marketplace, Actions, Packages), Atlassian (one account → Jira, Confluence, Marketplace), and Stripe (one account → Dashboard, Atlas, Stripe Apps).
|
||||
|
||||
The shared identity store is a **single Supabase project**. All products point to the same `NEXT_PUBLIC_SUPABASE_URL` and read from the same `auth.users` table. No synchronisation jobs, no duplicate user records.
|
||||
|
||||
### ADR-003B: Supabase Auth as the Identity Provider
|
||||
|
||||
**Supabase Auth** is the identity layer for the entire ecosystem. It was chosen over:
|
||||
|
||||
- **Better Auth** — excellent self-hosted option, but requires a Postgres database to be provisioned separately. Since the Marketplace and `worldwideview-web` have no existing database, Supabase provides auth + Postgres in a single managed service with zero extra infrastructure.
|
||||
- **NextAuth v5** — already present in the Local App for local access control, but it is not a full identity platform. Missing 2FA, RBAC, and a proper OAuth server model. Not suitable as an ecosystem-wide IdP.
|
||||
- **Clerk** — fastest setup and best Stripe integration, but ~$25–50/month at low user counts, per-MAU pricing at scale, and user data is stored on Clerk's servers. Vendor lock-in is unacceptable for a product that holds plugin and subscription data.
|
||||
|
||||
Supabase Auth provides:
|
||||
- Email + password, Google OAuth, GitHub OAuth, and magic link — all configured in the Supabase dashboard with no provider code
|
||||
- `@supabase/ssr` package with first-class Next.js App Router support (server components, middleware, server actions)
|
||||
- Cookie-based sessions that can be scoped to the parent domain
|
||||
- Free tier is sufficient for early-stage Marketplace; Pro plan ($25/month) unlocks unlimited MAU
|
||||
|
||||
### ADR-003C: `worldwideview.dev` (worldwideview-web repo) is the Ecosystem Auth Host
|
||||
|
||||
The login and account registration UI lives at **`worldwideview.dev`** — the apex domain, served by the `worldwideview-web` repository. Three alternatives were considered:
|
||||
|
||||
**Option A — Each app has its own login page**
|
||||
Rejected. Each product renders its own login form against the shared Supabase project. Browser `localStorage` (used by client-side Supabase) is domain-scoped and cannot be shared across subdomains. This means a user logged in at `marketplace.worldwideview.dev` would not be recognised at `app.worldwideview.dev`. Solving this in each app separately creates duplicated middleware and fragile cookie coordination.
|
||||
|
||||
**Option B — Marketplace owns the login page**
|
||||
Rejected. The Cloud App would be permanently subordinate to the Marketplace for authentication. If the Marketplace is down, Cloud App users cannot log in. Also creates a confusing UX: users navigate to `app.worldwideview.dev` and are immediately bounced to `marketplace.worldwideview.dev` just to authenticate.
|
||||
|
||||
**Option C — Dedicated `accounts.worldwideview.dev` subdomain**
|
||||
Seriously considered. A neutral auth subdomain is the cleanest long-term architecture. Rejected for now because it requires a third Next.js deployment and a third Coolify application. The same result is achieved by hosting auth on the apex domain itself (`worldwideview.dev`), which is already managed by `worldwideview-web` and is the identity host by virtue of owning the root domain.
|
||||
|
||||
**Chosen: Apex domain as auth host.** The `worldwideview-web` repo becomes the auth surface for the whole ecosystem:
|
||||
|
||||
| Path | Type | Purpose |
|
||||
|---|---|---|
|
||||
| `/` | Static | Landing page (marketing) |
|
||||
| `/about`, `/docs`, `/plugins` | Static | Marketing content |
|
||||
| `/login` | Dynamic (SSR) | Shared login for all products |
|
||||
| `/signup` | Dynamic (SSR) | New account creation |
|
||||
| `/cloud` | Dynamic (SSR) | Cloud plan registration and subscription |
|
||||
| `/accounts/*` | Dynamic (SSR) | Account management, billing, API keys |
|
||||
| `/api/auth/callback` | Dynamic (SSR) | OAuth redirect handler (Google, GitHub) |
|
||||
|
||||
**Why the apex domain is correct:** A session cookie set on `worldwideview.dev` is automatically inherited by all subdomains (`marketplace.worldwideview.dev`, `app.worldwideview.dev`, and any future product). This is the same mechanism used by Stripe — `stripe.com/login` sets the session that `dashboard.stripe.com` reads.
|
||||
|
||||
### ADR-003D: Cross-Subdomain Session Sharing via Parent Domain Cookie
|
||||
|
||||
Supabase Auth session cookies are explicitly scoped to the parent domain so that all products share the same session without additional coordination:
|
||||
|
||||
```typescript
|
||||
// Applied in worldwideview-web middleware and all Supabase server clients
|
||||
cookieOptions: {
|
||||
domain: '.worldwideview.dev', // leading dot = all subdomains inherit
|
||||
path: '/',
|
||||
sameSite: 'lax',
|
||||
secure: true, // HTTPS required — see local dev below
|
||||
}
|
||||
```
|
||||
|
||||
Each product (Marketplace, Cloud App) reads this cookie to get the authenticated user, then calls `supabase.auth.getUser()` server-side to validate the session. No cross-app API calls for authentication.
|
||||
|
||||
**Logout** must clear the cookie on the parent domain, not the subdomain, or the session will persist across products.
|
||||
|
||||
### ADR-003E: `worldwideview-web` Converts from Static Export to Mixed Static/SSR
|
||||
|
||||
The current `worldwideview-web` uses `output: "export"` in `next.config.ts`, forcing every page to be a static HTML file served by Nginx. This is removed.
|
||||
|
||||
Without `output: "export"`, Next.js App Router applies per-route rendering:
|
||||
- Pages that do not call `cookies()`, `headers()`, or other dynamic functions are **statically generated at build time** — marketing pages remain fast and CDN-cached with no change required.
|
||||
- Pages that call `cookies()` (all auth pages using `@supabase/ssr`) are **server-rendered on request**.
|
||||
|
||||
The Docker deployment changes from an Nginx static image to a Node.js runtime image. The Coolify application is updated in-place — no new Coolify application is needed.
|
||||
|
||||
### ADR-003F: `wwv.local` Local Development Environment
|
||||
|
||||
Because the parent-domain cookie requires `secure: true` (HTTPS only), local development using `localhost` will not replicate production session-sharing behaviour. A local HTTPS domain is required.
|
||||
|
||||
The project adopts `wwv.local` as the local development TLD with a self-signed certificate:
|
||||
|
||||
| Local URL | Maps to | Purpose |
|
||||
|---|---|---|
|
||||
| `wwv.local` | worldwideview-web on port 3001 | Landing + auth |
|
||||
| `marketplace.wwv.local` | worldwideview-marketplace on port 3002 | Marketplace |
|
||||
| `app.wwv.local` | worldwideview main app on port 3000 | Local App / Cloud App |
|
||||
|
||||
This setup is a deliberate investment: it ensures that cross-subdomain auth, redirect flows, and cookie behaviour can be tested locally before production deployment. The setup cost is a one-time `mkcert` install and hosts file edit per developer machine.
|
||||
|
||||
Setup (documented in each repo's README):
|
||||
```bash
|
||||
# Install mkcert (once per machine)
|
||||
# macOS: brew install mkcert && mkcert -install
|
||||
# Windows: choco install mkcert && mkcert -install
|
||||
|
||||
mkcert "*.wwv.local" wwv.local
|
||||
# Add to hosts: 127.0.0.1 wwv.local marketplace.wwv.local app.wwv.local
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Security Constraints (from Pre-Mortem Review)
|
||||
|
||||
The following risks were identified and mitigated before implementation:
|
||||
|
||||
| Risk | Mitigation |
|
||||
|---|---|
|
||||
| Supabase anon key can read all rows if RLS is disabled | Row Level Security (RLS) MUST be enabled on all app-specific tables (`MarketplaceUser`, `InstalledPlugin`). Policy: `using (id = auth.uid())`. Server routes use `SUPABASE_SERVICE_ROLE_KEY` which bypasses RLS by design. |
|
||||
| PKCE authorization code replay attack | The authorization code is deleted from the database transactionally at the moment of redemption. Any subsequent attempt receives `400 invalid_grant`. |
|
||||
| Supabase free tier limits magic link email to 2/hour per address | A custom SMTP provider (Resend) is configured in Supabase project settings before magic link is enabled in production. |
|
||||
| `MarketplaceUser` becomes orphaned when `auth.users` row is deleted | A Postgres trigger on `auth.users` DELETE cascades to `MarketplaceUser` and all related rows. |
|
||||
| Ed25519 signing key rotation causes token rejection at Data Engines | Signing keys are stored in a `SigningKey` DB table, not env vars. The JWKS endpoint serves all non-revoked keys simultaneously. During rotation, the old key is marked `retiring` and kept in JWKS for 10 minutes before being marked `revoked`. |
|
||||
|
||||
---
|
||||
|
||||
## Marketplace PKCE OAuth Server (Relation to ADR-001)
|
||||
|
||||
The Marketplace acts as the **OAuth 2.0 Authorization Server** in the ADR-001 PKCE flow. Supabase Auth handles user identity; a thin custom layer handles the code exchange:
|
||||
|
||||
1. Local App redirects user to `marketplace.worldwideview.dev/api/oauth/authorize`
|
||||
2. Marketplace validates the Supabase session (or redirects to `worldwideview.dev/login`)
|
||||
3. User sees consent screen and approves
|
||||
4. Marketplace issues a short-lived authorization code (60s TTL), redirects to Local App
|
||||
5. Local App exchanges code + `code_verifier` for a long-lived API Key
|
||||
6. Subsequent plugin connections use the API Key to request 5-minute EdDSA JWTs (ADR-001B)
|
||||
|
||||
This is not a new Supabase feature — it is custom Next.js API routes sitting on top of the existing Supabase Auth session.
|
||||
|
||||
---
|
||||
|
||||
## Consequences
|
||||
|
||||
- **One Supabase project** is a shared dependency across `worldwideview-web`, `worldwideview-marketplace`, and `worldwideview` (Cloud App). A Supabase outage affects all products simultaneously. This is an accepted tradeoff at current scale; the mitigation is Supabase's SLA and free-tier generous limits.
|
||||
- **`worldwideview-web` must run as a Node.js server**, not a static Nginx container. This increases Coolify resource usage marginally but enables all auth functionality.
|
||||
- **Local development requires `mkcert` setup** (one-time, ~5 minutes). This is a deliberate decision to prevent a class of production bugs that cannot be caught with `localhost`.
|
||||
- **The old `cloud-auth-architecture.md` rule is invalidated.** That rule stated `app.worldwideview.dev` owns all login UI and the Marketplace redirects there. The reverse is now true. That rules file must be updated to reference this ADR.
|
||||
- **Upgrade path is clear:** If the Marketplace matures into a platform that third-party developers build against (issuing OAuth tokens to external apps), the existing PKCE layer is extended without changing the user table or Supabase project. The identity layer is already decoupled from the token exchange layer.
|
||||
@@ -0,0 +1,88 @@
|
||||
# ADR-0004: Supabase Session Cookies Are httpOnly Across the Ecosystem
|
||||
|
||||
## Status
|
||||
Accepted *(2026-05-25)*
|
||||
|
||||
## Date
|
||||
2026-05-25
|
||||
|
||||
## Related
|
||||
- **Builds on:** ADR-0003 (Shared Identity & Ecosystem Auth Host) — defines the parent-domain cookie scoping (`.worldwideview.dev` prod, `.wwv.local` dev) that this ADR hardens.
|
||||
|
||||
---
|
||||
|
||||
## Context
|
||||
|
||||
ADR-0003 established that a single Supabase session cookie scoped to the parent domain is inherited by every product subdomain (`marketplace.*`, `app.*`, the apex). The cookie carries a base64-encoded access token, refresh token, and the full user record. By default `@supabase/ssr` does NOT set `httpOnly` on this cookie because the browser client (`createBrowserClient`) needs to read it via `document.cookie` to compute `getSession()` synchronously without a network round-trip.
|
||||
|
||||
That default is fine for apps that perform their auth reads on the client. It is **not fine for this ecosystem.** Three observations forced the decision:
|
||||
|
||||
1. The `worldwideview-marketplace` repo already shipped with `httpOnly: true` in `buildCookieOptions()`. Its install gate (`requireSupabaseUser` in `src/lib/auth/requireSession.ts`) and every API route read the session through the server client (`createServerClient`), so a non-readable cookie costs nothing.
|
||||
|
||||
2. The `worldwideview-web` repo originally omitted `httpOnly` and had a single client-side reader: `src/app/hub/layout.tsx` ran `supabase.auth.getSession()` inside a `useEffect`. During audit (2026-05-25), this was discovered as the *only* JS path that needed cookie readability — and it was an anti-pattern (auth gate via `useEffect` introduces a flash-of-unauthenticated-content and is replaceable with a server component).
|
||||
|
||||
3. With the cookie readable to JS, an XSS payload on **any** subdomain (`marketplace.*`, `app.*`, the apex itself) can exfiltrate the full session token. Given marketplace renders user-submitted plugin metadata, this is a real attack surface.
|
||||
|
||||
The choice was: keep client-side `getSession()` calls and accept the XSS exfiltration risk, or refactor reads to server-side and harden the cookie.
|
||||
|
||||
---
|
||||
|
||||
## Decision
|
||||
|
||||
**All Supabase session cookies in the WorldWideView ecosystem are set with `httpOnly: true`.** This is enforced in each app's `buildCookieOptions()` helper:
|
||||
|
||||
- `worldwideview-web/src/lib/supabase/cookieOptions.ts`
|
||||
- `worldwideview-marketplace/src/lib/supabase/cookieOptions.ts`
|
||||
- `worldwideview/src/lib/supabase/cookieOptions.ts` (cloud edition only — file is gated by `isCloud`)
|
||||
|
||||
Companion hard constraint: **client-side `supabase.auth.getSession()` / `getUser()` / `getClaims()` is forbidden everywhere in the ecosystem.** All auth reads happen server-side via:
|
||||
|
||||
- Server components / pages — call `createClient()` from `src/lib/supabase/server.ts`, then `auth.getClaims()` (validates against the auth server, doesn't trust the cookie).
|
||||
- API routes — same pattern, typically through a wrapper like `requireSupabaseUser(returnTo)`.
|
||||
- Middleware / proxy — Next.js 16's `proxy.ts` refreshes the session on every matched request and propagates rotated cookies onto the response.
|
||||
|
||||
If a future feature requires reading the session on the client, it MUST go through a server-rendered prop or a fetch to an internal API route that performs the read server-side. Adding a new client-side auth read is a regression.
|
||||
|
||||
### Implementation details
|
||||
|
||||
```ts
|
||||
// Shared shape across all three apps:
|
||||
export function buildCookieOptions() {
|
||||
return {
|
||||
domain: resolveCookieDomain(process.env.NEXT_PUBLIC_WWV_COOKIE_DOMAIN),
|
||||
path: '/',
|
||||
sameSite: 'lax' as const,
|
||||
secure: true,
|
||||
httpOnly: true, // ← this ADR
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
The `proxy.ts` middleware in worldwideview-web (and the equivalent server-client invocations everywhere else) passes `cookieOptions: buildCookieOptions()` into `createServerClient` so token refreshes inherit the flag automatically.
|
||||
|
||||
---
|
||||
|
||||
## Consequences
|
||||
|
||||
**Positive:**
|
||||
- XSS on any subdomain can no longer read the session token. The auth server still validates each request, so even a forged cookie has no value.
|
||||
- Auth state is server-rendered, removing the flash-of-unauthenticated-content on protected routes (previously visible at `/hub`).
|
||||
- Codebase is consistent — three apps, one cookie configuration, one set of read patterns.
|
||||
|
||||
**Negative / accepted tradeoffs:**
|
||||
- Client-side `supabase.auth.*` reads are dead. Any contributor who has worked with `@supabase/supabase-js` will instinctively reach for `getSession()` in a `useEffect`. Code review must catch this.
|
||||
- Token refresh on stale tabs requires a server round-trip through `proxy.ts` rather than a client-side refresh. Adds ~10-50ms to the first request after expiry; acceptable.
|
||||
- Browser-side debugging is slightly harder — you can't paste `await supabase.auth.getUser()` into the devtools console. Use server logs or a dedicated `/api/debug/whoami` route instead.
|
||||
|
||||
**Verification at adoption (2026-05-25):**
|
||||
- `worldwideview-web/src/app/hub/layout.tsx` refactored from client useEffect to server component (`getClaims()` + `redirect()`); test rewritten accordingly.
|
||||
- Browser confirmation: after sign-out + sign-in, `document.cookie` no longer contains `sb-<ref>-auth-token.0/.1`; only the dev-mode `__next_hmr_refresh_hash__` cookie remains visible to JS.
|
||||
- Marketplace and WWV cloud edition were already compliant; no behavior change for them.
|
||||
|
||||
---
|
||||
|
||||
## Enforcement
|
||||
|
||||
- Code review must flag any import of `createBrowserClient` from `@supabase/ssr` if the call site is in a `"use client"` component and invokes `auth.*` directly.
|
||||
- Future ESLint rule: ban `createBrowserClient` + `auth.getUser|getSession|getClaims` combinations. (Not implemented yet — follow-up.)
|
||||
- The marketplace browser client (`worldwideview-marketplace/src/lib/supabase/client.ts`) exists but is unused; consider deleting it in a future cleanup pass.
|
||||
@@ -0,0 +1,167 @@
|
||||
# ADR-001 Pre-flight Audit — 2026-05-21
|
||||
|
||||
**Auditor:** Claude (ADR-001 Local App workstream) **Branch:** `feat/adr-001-local-app`
|
||||
**Status:** Complete — see gate summary in §6
|
||||
|
||||
This document records the six step-0 checklist items from the master deploy plan
|
||||
(`i-want-you-to-delightful-candle.md`, §"Deploy Order") before any ADR-001 code
|
||||
lands on production.
|
||||
|
||||
---
|
||||
|
||||
## 1. Coolify Env-Var Audit
|
||||
|
||||
Swept every `JWT_*`, `TICKET_*`, `JWKS_*`, and `AUTH_*` variable across the three
|
||||
live services. Values are masked; only presence is recorded.
|
||||
|
||||
### Debris check
|
||||
|
||||
| Service | Coolify resource | `JWT_*` | `TICKET_*` | `JWKS_*` | `AUTH_SECRET` | Decision |
|
||||
|---|---|---|---|---|---|---|
|
||||
| Local App | `worldwideview-demo` | — | — | — | ✓ set | nothing to remove |
|
||||
| Data Engine | `wwv-engine-stack` | — | — | — | — | nothing to remove |
|
||||
| Marketplace | `worldwideview-marketplace` | — | — | — | — | nothing to remove |
|
||||
|
||||
**Result: No debris from the previous failed deploy.** All three services are clean.
|
||||
No removals required.
|
||||
|
||||
### ADR-001 vars — gaps to fill in deploy steps 1–2
|
||||
|
||||
| Service | Missing var | Required by | When to set | Notes |
|
||||
|---|---|---|---|---|
|
||||
| `worldwideview-demo` | `ENCRYPTION_MASTER_KEY` | **C1 hard gate** | **Step 1 — first action** | Without it the app boots but step-1 code will refuse to start |
|
||||
| `worldwideview-demo` | `MARKETPLACE_URL` | C3 ticketClient | Step 1 | Server-side token exchange endpoint |
|
||||
| `worldwideview-demo` | `NEXT_PUBLIC_WWV_MARKETPLACE_URL` | C3/C5 client | Step 1 | Client-side Marketplace link |
|
||||
| `worldwideview-demo` | `PROXY_HOST_ALLOWLIST` | C2 SSRF | Step 1 | Set to `"*"` (observation mode); tighten in step 7c |
|
||||
| `worldwideview-demo` | `NEXT_PUBLIC_WWV_TICKET_AUTH_PLUGINS` | C5 flag | Step 6 | Leave empty (dormant) until step 6 cutover |
|
||||
| `worldwideview-marketplace` | `DATABASE_URL`, `AUTH_SECRET` | A basics | Step 2 | Marketplace cannot function without these |
|
||||
| `worldwideview-marketplace` | EdDSA signing key + JWKS endpoint | A1–A2 | Step 2 | Required for `/api/auth/exchange` to sign tickets |
|
||||
| `wwv-engine-stack` | JWKS / JWT public-key config | B JWKS wiring | Step 4 | See §5 — not blocking until cutover |
|
||||
|
||||
---
|
||||
|
||||
## 2. Data Engine `main` Branch State
|
||||
|
||||
**Repo:** `silvertakana/wwv-data-engine`
|
||||
**Branch audited:** `main` (HEAD matches `feat/adr-001-data-engine`)
|
||||
|
||||
The `main` branch is **not** in a rolled-back clean state. The decentralised auth
|
||||
work from the prior attempt was **retained and fully merged** (PR #5
|
||||
`feature/decentralised-plugin-auth-data-engine`, PR #6 `chore/standardise-ci`), with
|
||||
four additional fix commits on top.
|
||||
|
||||
**Auth code present in `main`:**
|
||||
|
||||
- Dependencies: `@fastify/jwt ^10`, `get-jwks ^11`, `jose ^6`
|
||||
- `websocket.ts` verifies EdDSA JWTs:
|
||||
```
|
||||
allowedIss: 'https://marketplace.worldwideview.dev'
|
||||
algorithms: ['EdDSA']
|
||||
clockTolerance: 60
|
||||
expectedAud: process.env.ENGINE_ID || 'wwv-data-engine'
|
||||
```
|
||||
|
||||
**Env-gated bypass (commit `e3e2940`):**
|
||||
`WWV_SKIP_WS_AUTH=true` is set on `wwv-engine-stack`. When true, every WS connection
|
||||
is pre-authenticated with no JWT required. **This bypass is currently load-bearing:**
|
||||
the JWKS endpoint is not yet wired (`websocket.ts:23` comment confirms), so the
|
||||
engine cannot verify real tokens. `WWV_SKIP_WS_AUTH=true` must stay until Workstream
|
||||
B wires JWKS (deploy step 4).
|
||||
|
||||
**Uncommitted working-tree WIP (not blocking steps 1–3):**
|
||||
`src/server.ts`, `src/websocket.ts`, `src/websocket.spec.ts` modified; untracked
|
||||
`HANDOFF.md`, `src/startup-checks.ts`, `vitest.config.ts`. The Data Engine
|
||||
workstream has unfinished work not yet committed. Must be resolved before step 4.
|
||||
|
||||
---
|
||||
|
||||
## 3. Dormant Routes / Flags Already in Production
|
||||
|
||||
| Flag / Route | Service | Current value | Introduced | Notes |
|
||||
|---|---|---|---|---|
|
||||
| `WWV_SKIP_WS_AUTH` | `wwv-engine-stack` | `true` (load-bearing) | 2026-05-20 | Engine bypass — must stay `true` until JWKS wired (step 4) |
|
||||
|
||||
No other ADR-001 feature flags are active in production. The old no-auth data path
|
||||
is still the only path through the Data Engine.
|
||||
|
||||
---
|
||||
|
||||
## 4. `ENCRYPTION_MASTER_KEY` Gate (C1)
|
||||
|
||||
**Status: FAIL — not set on `worldwideview-demo`**
|
||||
|
||||
The `ENCRYPTION_MASTER_KEY` env var is absent from the live Local App. Once
|
||||
`src/instrumentation.ts` boot validation ships (deploy step 1), the app will
|
||||
**refuse to start** if this var is missing.
|
||||
|
||||
**Action required before deploy step 1:**
|
||||
Generate a 32-character key (`openssl rand -hex 16`) and set `ENCRYPTION_MASTER_KEY`
|
||||
on `worldwideview-demo` in Coolify. This is the **first action of deploy step 1** and
|
||||
blocks all subsequent steps.
|
||||
|
||||
---
|
||||
|
||||
## 5. SDK Delivery Decision (Gate for Workstream B)
|
||||
|
||||
**Status: OPEN — operator to confirm**
|
||||
|
||||
No evidence of a published `@worldwideview/wwv-plugin-sdk` package in the deployed
|
||||
services. The `auth-contracts.ts` types (`TokenExchangeRequest`,
|
||||
`TokenExchangeResponse`, `PluginTicket`, `MarketplaceSessionToken`) currently live in
|
||||
the Local App's bundled SDK package.
|
||||
|
||||
Workstream B JWKS wiring requires a decision on how the engine receives the
|
||||
Marketplace public key:
|
||||
- **Option A:** Ed25519 public key as a Coolify env var (simplest)
|
||||
- **Option B:** Remote JWKS URL env var — engine fetches key from
|
||||
`https://marketplace.worldwideview.dev/.well-known/jwks.json` at startup
|
||||
|
||||
**Cross-repo issuer alignment note:** The engine hard-codes
|
||||
`allowedIss: 'https://marketplace.worldwideview.dev'`. The Local App's `MARKETPLACE_URL`
|
||||
config defaults to `https://app.worldwideview.dev`. Confirm that the live Marketplace
|
||||
issues JWTs with `iss: https://marketplace.worldwideview.dev` before step 5 smoke test.
|
||||
|
||||
This decision must be made and documented before deploy step 4.
|
||||
|
||||
---
|
||||
|
||||
## 6. Gate Summary
|
||||
|
||||
| Gate | Status | Blocks deploy step | Action |
|
||||
|---|---|---|---|
|
||||
| No legacy JWT/TICKET debris | ✅ PASS | — | None |
|
||||
| `ENCRYPTION_MASTER_KEY` set on Local App | ❌ FAIL | **Step 1** | Set as first action of step 1 |
|
||||
| Marketplace configured (DB, auth, signing key) | ❌ FAIL | **Step 2** | Configure `worldwideview-marketplace` in Coolify |
|
||||
| SDK delivery decision confirmed | ⚠️ OPEN | Step 4 | Operator decision needed |
|
||||
| Data Engine JWKS wired | ❌ FAIL | Step 4 / cutover | `WWV_SKIP_WS_AUTH` bypass active until then |
|
||||
| Data Engine WIP committed | ⚠️ OPEN | Step 4 | Not blocking steps 1–3 |
|
||||
| Issuer alignment confirmed | ⚠️ OPEN | Step 5 smoke test | Verify `iss` claim matches engine `allowedIss` |
|
||||
|
||||
**Top pre-cutover risks:**
|
||||
|
||||
1. **JWKS not wired on the engine** — `WWV_SKIP_WS_AUTH=true` is the only thing
|
||||
keeping streams alive. If this flag is ever accidentally unset, all WebSocket
|
||||
streams break immediately.
|
||||
2. **Marketplace under-configured** — token exchange will error until step 2 env vars
|
||||
are set. `worldwideview-marketplace` currently has only infra vars (NIXPACKS,
|
||||
REDIS, REGISTRY_PRIVATE_KEY).
|
||||
3. **`ENCRYPTION_MASTER_KEY` missing** — deploy step 1 will trigger a boot refusal
|
||||
if not set first. This is the riskiest item in the pre-cutover phase per the
|
||||
master plan.
|
||||
|
||||
---
|
||||
|
||||
## 7. Cleanup Log
|
||||
|
||||
**Removed this step (2026-05-21):**
|
||||
|
||||
| Resource | Type | UUID | Reason |
|
||||
|---|---|---|---|
|
||||
| `wwv-app-stack` | Coolify service | `h3gtnyotl6b7007hudlfqyf9` | Operator-confirmed deprecated |
|
||||
|
||||
**Remaining cleanup decisions (operator to confirm before step 4):**
|
||||
|
||||
| Resource | Type | UUID | Notes |
|
||||
|---|---|---|---|
|
||||
| `worldwideview web` | Application | `cisr3bruyyvvoeym41dexxa3` | Repo `silvertakana/worldwideview-web`; only REDIS+AISSTREAM vars — appears stale. Verify before removing. |
|
||||
| `wwv-data-engine-legacy` | Application | `sj8519kr561va8ktcdq166hn` | Repo `wwv-data-engine-internal`, branch `master`; appears superseded by `wwv-engine-stack`. Verify before removing. |
|
||||
@@ -0,0 +1,79 @@
|
||||
# ADR-001 Feature Flags
|
||||
|
||||
Single source of truth for all feature flags introduced by
|
||||
[ADR-0001](architecture/decisions/adr-0001-decentralized-plugin-auth-and-ssrf-mitigation.md)
|
||||
(Decentralized Plugin Auth + SSRF Mitigation).
|
||||
|
||||
**Keep the per-environment table current** whenever a flag is set, changed, or
|
||||
removed in Coolify. Drift between staging and production is the primary paper-cut
|
||||
this doc exists to prevent.
|
||||
|
||||
---
|
||||
|
||||
## Flag Inventory
|
||||
|
||||
### 5 Master-Plan Flags
|
||||
|
||||
| Flag | Repo | Default | Meaning |
|
||||
|---|---|---|---|
|
||||
| `NEXT_PUBLIC_WWV_TICKET_AUTH_PLUGINS` | **Local App** | `""` (empty = dormant) | Comma-separated plugin IDs that require WS first-message auth (e.g. `aviation,maritime`). Empty or unset → ticket auth disabled for all plugins. Set *after* Marketplace + Data Engine are deployed (step 6). |
|
||||
| `REQUIRE_TICKET_AUTH` | **Data Engine** | `false` | When `true`, the engine rejects any WS connection that does not present a valid ticket. Global — applies to all plugins. Replaces `WWV_SKIP_WS_AUTH=false` once JWKS is wired (step 7a). |
|
||||
| `REQUIRE_TICKET_AUTH_PLUGINS` | **Data Engine** | `""` | Comma-separated plugin IDs for per-plugin enforcement before enabling the global flag. Not yet implemented (see Divergence Note below). |
|
||||
| `ENFORCE_ORIGIN_ALLOWLIST` | **Data Engine** | `false` | When `true`, the engine rejects connections from Origins not in its configured allowlist. Enable after populating the allowlist from observed traffic (step 7b). |
|
||||
| `PROXY_HOST_ALLOWLIST` | **Local App** | `""` (deny all) | SSRF allowlist for the camera / iframe proxy route. `""` or unset = deny all (safe default). `"*"` = permissive + logs WARN per host (observation mode). Comma-separated list = explicit allowlist. Ship `"*"` initially; tighten to an explicit list after one week of log observation (step 7c). |
|
||||
|
||||
### Deployed Reality: `WWV_SKIP_WS_AUTH`
|
||||
|
||||
> **Divergence note:** The Data Engine workstream implemented a single global bypass
|
||||
> flag (`WWV_SKIP_WS_AUTH`) instead of the three granular master-plan flags
|
||||
> (`REQUIRE_TICKET_AUTH`, `REQUIRE_TICKET_AUTH_PLUGINS`, `ENFORCE_ORIGIN_ALLOWLIST`).
|
||||
> The master-plan flags remain the target architecture and must be implemented before
|
||||
> step 7. `WWV_SKIP_WS_AUTH` is the current interim control.
|
||||
|
||||
| Flag | Repo | Default | Meaning |
|
||||
|---|---|---|---|
|
||||
| `WWV_SKIP_WS_AUTH` | **Data Engine** | `false` | When `true`, every WS connection is pre-authenticated — no JWT is checked. **Currently `true` in production and load-bearing** (JWKS not yet wired; the engine cannot verify real tokens). Must stay `true` until deploy step 4 wires JWKS. Flip to `false` as part of step 5 smoke test, replacing it with `REQUIRE_TICKET_AUTH=true`. |
|
||||
|
||||
---
|
||||
|
||||
## Per-Environment Table
|
||||
|
||||
Update this table whenever a flag changes in Coolify.
|
||||
|
||||
| Flag | Local dev | Staging | Production | Last updated |
|
||||
|---|---|---|---|---|
|
||||
| `NEXT_PUBLIC_WWV_TICKET_AUTH_PLUGINS` | `""` (.env.example) | `""` (not set) | `""` (not set) | 2026-05-21 |
|
||||
| `REQUIRE_TICKET_AUTH` | N/A | N/A | N/A (not yet implemented) | — |
|
||||
| `REQUIRE_TICKET_AUTH_PLUGINS` | N/A | N/A | N/A (not yet implemented) | — |
|
||||
| `ENFORCE_ORIGIN_ALLOWLIST` | N/A | N/A | N/A (not yet implemented) | — |
|
||||
| `PROXY_HOST_ALLOWLIST` | `"*"` (.env.example) | TBD — set before step 5 | not set (= deny all) | 2026-05-21 |
|
||||
| `WWV_SKIP_WS_AUTH` | `false` | TBD — set before step 4 | `true` (**load-bearing**) | 2026-05-20 |
|
||||
|
||||
---
|
||||
|
||||
## Rollout Sequence
|
||||
|
||||
The sequence in which flags are set during the ADR-001 deploy order:
|
||||
|
||||
| Deploy step | Service | Flag change | Notes |
|
||||
|---|---|---|---|
|
||||
| Step 1 | Local App | Set `PROXY_HOST_ALLOWLIST="*"` | Observation mode — watch WARN logs for one week |
|
||||
| Step 3 | Local App | `NEXT_PUBLIC_WWV_TICKET_AUTH_PLUGINS=""` confirmed empty | Dormant — no change needed, just confirm |
|
||||
| Step 4 | Data Engine | JWKS wired; `WWV_SKIP_WS_AUTH` remains `true` | Both paths exist, neither enforced |
|
||||
| Step 5 (staging) | Local App | `NEXT_PUBLIC_WWV_TICKET_AUTH_PLUGINS=test-synthetic` | Smoke test only — revert after |
|
||||
| Step 5 (staging) | Data Engine | `WWV_SKIP_WS_AUTH=false` | Prove real JWT verification end-to-end |
|
||||
| Step 6 | Local App | `NEXT_PUBLIC_WWV_TICKET_AUTH_PLUGINS=<first-real-plugin>` | One plugin at a time, 24 h soak |
|
||||
| Step 6 | Data Engine | `REQUIRE_TICKET_AUTH_PLUGINS=<same-plugin>` | Mirror Local App change |
|
||||
| Step 7a | Data Engine | `REQUIRE_TICKET_AUTH=true` | Global default-deny; 24 h soak |
|
||||
| Step 7b | Data Engine | `ENFORCE_ORIGIN_ALLOWLIST=true` | After populating allowlist from observed connections |
|
||||
| Step 7c | Local App | `PROXY_HOST_ALLOWLIST=<observed-list>` | Replace `"*"` with explicit host list |
|
||||
|
||||
---
|
||||
|
||||
## Rollback
|
||||
|
||||
Every step is independently revertable by flipping its single flag back. The old
|
||||
no-auth data path remains wired throughout steps 1–6 and is only superseded at
|
||||
step 7a. If anything breaks, removing the plugin from
|
||||
`NEXT_PUBLIC_WWV_TICKET_AUTH_PLUGINS` immediately restores the old path for that
|
||||
plugin.
|
||||
@@ -0,0 +1,258 @@
|
||||
# SECURITY.md -- Phase 3: Local App PKCE + SSRF Proxy Hardening
|
||||
|
||||
**Audit date:** 2026-05-24
|
||||
**Phase:** 3 -- Local App PKCE + SSRF Proxy Hardening
|
||||
**ASVS Level:** 2
|
||||
**Audit mode:** Retroactive-STRIDE (no formal threat model at plan time; register constructed from implementation)
|
||||
**block_on:** open
|
||||
|
||||
---
|
||||
|
||||
## Threat Register
|
||||
|
||||
| ID | Category | Description | Disposition | Status |
|
||||
|----|----------|-------------|-------------|--------|
|
||||
| T01 | SSRF | Proxy endpoints use raw `fetch` instead of `safeFetch` | mitigate | CLOSED |
|
||||
| T02 | SSRF | `PROXY_HOST_ALLOWLIST` not enforced | mitigate | CLOSED |
|
||||
| T03 | SSRF | Private IP ranges not blocked | mitigate | CLOSED |
|
||||
| T04 | SSRF/DNS-rebinding | DNS resolved multiple times; IP not pinned between lookup and connect | mitigate | CLOSED |
|
||||
| T05 | SSRF/Open-redirect | Proxy follows 3xx redirects, enabling open-redirect chains | mitigate | CLOSED |
|
||||
| T06 | SSRF | iframe proxy previously used raw `fetch` with no size cap | mitigate | CLOSED |
|
||||
| T07 | Spoofing | PKCE state not validated; forged state accepted | mitigate | CLOSED |
|
||||
| T08 | Spoofing | PKCE state cookie not `__Host-` prefixed on HTTPS | mitigate | CLOSED |
|
||||
| T09 | Spoofing | PKCE state/verifier cookies not `httpOnly`, missing `SameSite` | mitigate | CLOSED |
|
||||
| T10 | Spoofing | PKCE state/verifier cookies too long-lived (>10 min) | mitigate | CLOSED |
|
||||
| T11 | Elevation | `code_verifier` cookie reusable after exchange (replay) | mitigate | CLOSED |
|
||||
| T12 | Tampering | `ENCRYPTION_MASTER_KEY` unset falls back to zero-key silently | mitigate | CLOSED |
|
||||
| T13 | Elevation | WsClient sends `subscribe` before auth (`onopen` path) | mitigate | CLOSED |
|
||||
| T14 | Elevation | WsClient sends `subscribe` before auth (`subscribe()` method -- race, already-open connection) | mitigate | OPEN (BLOCKER) |
|
||||
|
||||
---
|
||||
|
||||
## Verification Evidence
|
||||
|
||||
### T01 -- Proxy endpoints use `safeFetch`
|
||||
|
||||
All three user-facing proxy routes import and call `safeFetch`, not raw `fetch`:
|
||||
|
||||
- `src/app/api/camera/proxy/route.ts:6,27` -- `import { safeFetch }` + `await safeFetch(targetUrl, ...)`
|
||||
- `src/app/api/camera/proxy/iframe/route.ts:6,32` -- `import { safeFetch }` + `await safeFetch(targetUrl, ...)`
|
||||
- `src/app/api/camera/proxy/stream/route.ts:6,31` -- `import { safeFetch }` + `await safeFetch(targetUrl, ...)`
|
||||
|
||||
**Status: CLOSED**
|
||||
|
||||
---
|
||||
|
||||
### T02 -- `PROXY_HOST_ALLOWLIST` enforced
|
||||
|
||||
`src/lib/security/ssrf.ts:25-42` -- `checkHostAllowlist()` is called at the top of `safeFetch` before any network I/O. Behavior:
|
||||
- Unset env var: throws `SSRF Error: PROXY_HOST_ALLOWLIST is not configured`
|
||||
- Empty string: throws same error
|
||||
- `"*"`: warns and permits (permissive mode, documented)
|
||||
- Specific list: rejects unlisted hostnames
|
||||
|
||||
Covered by unit tests in `src/lib/security/ssrf.spec.ts:63-82`.
|
||||
|
||||
**Status: CLOSED**
|
||||
|
||||
---
|
||||
|
||||
### T03 -- Private IP ranges blocked
|
||||
|
||||
`src/lib/security/ssrf.ts:4-9` -- `isPrivateIP()` covers:
|
||||
- `127.*`, `10.*`, `192.168.*`, `169.254.*` (AWS/GCP metadata), `0.*`
|
||||
- `172.16-31.*`
|
||||
- IPv6: `::1`, `fc*`, `fd*`, `fe80*`
|
||||
|
||||
Called twice: once against the literal URL hostname (line 56) and once against the resolved IP (line 66).
|
||||
|
||||
**Status: CLOSED**
|
||||
|
||||
---
|
||||
|
||||
### T04 -- DNS pinning via undici Agent
|
||||
|
||||
`src/lib/security/ssrf.ts:60-80` -- Single `dns.lookup()` call stores `resolvedIp` and `resolvedFamily`. A custom undici `Agent` is constructed with a `connect.lookup` override that always returns the pre-resolved address, preventing a second DNS resolution during TCP connect.
|
||||
|
||||
**Status: CLOSED**
|
||||
|
||||
---
|
||||
|
||||
### T05 -- Redirect following disabled
|
||||
|
||||
`src/lib/security/ssrf.ts:92` -- `redirect: "manual" as const` is passed to undici `fetch`. Verified by test at `ssrf.spec.ts:117-135` which asserts `callOpts.redirect === "manual"` and that only one fetch call is made when a 301 is returned.
|
||||
|
||||
**Status: CLOSED**
|
||||
|
||||
---
|
||||
|
||||
### T06 -- iframe proxy uses `safeFetch` with size cap
|
||||
|
||||
`src/app/api/camera/proxy/iframe/route.ts:6,32,39` -- Uses `safeFetch` with `maxSize: 5 * 1024 * 1024` and `timeout: MAX_IFRAME_DURATION_MS` (10 s). The previous raw-fetch vulnerability is no longer present.
|
||||
|
||||
**Status: CLOSED**
|
||||
|
||||
---
|
||||
|
||||
### T07 -- PKCE state validated in callback
|
||||
|
||||
`src/app/api/marketplace/callback/route.ts:10-15`:
|
||||
|
||||
```
|
||||
const stateCookie = req.cookies.get(`${cookiePrefix}pkce_state`)?.value;
|
||||
const urlState = req.nextUrl.searchParams.get("state");
|
||||
if (!stateCookie || urlState !== stateCookie) {
|
||||
return NextResponse.json({ error: "State mismatch" }, { status: 400 });
|
||||
}
|
||||
```
|
||||
|
||||
Both missing cookie and value mismatch are rejected.
|
||||
|
||||
**Status: CLOSED**
|
||||
|
||||
---
|
||||
|
||||
### T08 -- `__Host-` cookie prefix on HTTPS
|
||||
|
||||
`src/app/api/marketplace/connect/route.ts:22-23`:
|
||||
```
|
||||
const isHttps = req.nextUrl.protocol === "https:";
|
||||
const cookiePrefix = isHttps ? "__Host-" : "";
|
||||
```
|
||||
Same logic mirrored in `src/app/api/marketplace/callback/route.ts:7-8`. On HTTPS the cookies are named `__Host-pkce_state` and `__Host-pkce_verifier`, which browsers enforce must be `Secure`, `Path=/`, and no `Domain` attribute.
|
||||
|
||||
Note: the cookies use `path: "/api/marketplace/callback"`, not `path: "/"`. The `__Host-` prefix specification (RFC 6265bis) requires `Path=/`. This is a partial inconsistency -- the `__Host-` prefix technically requires `Path=/` to be valid per browsers that enforce the prefix spec strictly. In practice Chromium enforces `Path=/` for `__Host-` cookies and will silently reject the Set-Cookie header. This is flagged as an unregistered finding below but does not affect current HTTP (dev) deployments. **Treat as unregistered flag UF-01.**
|
||||
|
||||
**Status: CLOSED** (state validation logic present; see UF-01 for prefix/path mismatch)
|
||||
|
||||
---
|
||||
|
||||
### T09 -- `httpOnly` + `SameSite` on PKCE cookies
|
||||
|
||||
`src/app/api/marketplace/connect/route.ts:26-38`:
|
||||
- `httpOnly: true` -- set on both cookies
|
||||
- `sameSite: "lax"` -- set on both cookies
|
||||
- `secure: isHttps` -- conditional on protocol
|
||||
|
||||
**Status: CLOSED**
|
||||
|
||||
---
|
||||
|
||||
### T10 -- PKCE cookies short-lived (10 min)
|
||||
|
||||
`src/app/api/marketplace/connect/route.ts:30,38`: `maxAge: 60 * 10` (600 seconds = 10 minutes) on both state and verifier cookies.
|
||||
|
||||
**Status: CLOSED**
|
||||
|
||||
---
|
||||
|
||||
### T11 -- `code_verifier` cookie deleted post-exchange (single-use)
|
||||
|
||||
`src/app/api/marketplace/callback/route.ts:66-82` -- After successful token exchange, both `pkce_state` and `pkce_verifier` cookies are explicitly cleared by setting `maxAge: 0` with empty string values. This invalidates the cookies immediately on the response, preventing replay.
|
||||
|
||||
**Status: CLOSED**
|
||||
|
||||
---
|
||||
|
||||
### T12 -- `ENCRYPTION_MASTER_KEY` fails hard when unset
|
||||
|
||||
`src/lib/auth/encryption.ts:8-11`:
|
||||
```
|
||||
function getMasterKey(): string {
|
||||
const key = process.env.ENCRYPTION_MASTER_KEY;
|
||||
if (!key) throw new Error('[encryption] ENCRYPTION_MASTER_KEY env var is required');
|
||||
return key;
|
||||
}
|
||||
```
|
||||
No fallback. No zero-key. Both `encryptCredential` and `decryptCredential` call `getMasterKey()`.
|
||||
|
||||
**Status: CLOSED**
|
||||
|
||||
---
|
||||
|
||||
### T13 -- WsClient `onopen` sends auth before subscribe (ticket-auth path)
|
||||
|
||||
`src/core/data/WsClient.ts:84-107`:
|
||||
- When any subscription requires ticket auth, `engine.awaitingWelcome = true` is set and `subscribe` messages are NOT sent on `onopen`
|
||||
- Subscribes are deferred until `data.type === "welcome"` is received (lines 118-124)
|
||||
- A 3-second auth timeout closes the connection if welcome never arrives (lines 91-96)
|
||||
|
||||
**Status: CLOSED** (for the `onopen` path)
|
||||
|
||||
---
|
||||
|
||||
### T14 -- WsClient `subscribe()` method sends `subscribe` on already-open connection while `awaitingWelcome = true` (OPEN BLOCKER)
|
||||
|
||||
`src/core/data/WsClient.ts:198-211`:
|
||||
|
||||
```typescript
|
||||
public subscribe(pluginId: string, engineUrl: string) {
|
||||
engine.subscriptions.add(pluginId);
|
||||
this.connectEngine(engineUrl);
|
||||
this.send(engine, { action: "subscribe", pluginId }); // line 210
|
||||
}
|
||||
```
|
||||
|
||||
`this.send()` at line 210 checks only `ws.readyState === WebSocket.OPEN` before sending. It does **not** check `engine.awaitingWelcome`. If:
|
||||
1. Plugin A connects and triggers ticket auth (`awaitingWelcome = true`)
|
||||
2. Before the `welcome` arrives, Plugin B calls `subscribe()` on the same engine
|
||||
3. The WS is already OPEN, so `send()` fires -- Plugin B's `subscribe` message is sent to the server before auth is complete
|
||||
|
||||
This allows an unauthenticated subscribe frame to reach the data engine server. Whether the server accepts it depends on server-side enforcement, but the client does not enforce the auth-first guarantee for late joiners.
|
||||
|
||||
The `onopen` path (T13) is correctly gated. The `subscribe()` entry point is not.
|
||||
|
||||
**Impact:** A second plugin subscribing to an engine in the window between connection open and welcome receipt bypasses the client-side auth gate. The data engine must reject unauthenticated subscriptions server-side for defense in depth, but the ADR-001 intent was client-enforced first-message auth.
|
||||
|
||||
**Required fix:** In `subscribe()`, check `engine.awaitingWelcome` before calling `this.send()`. If `awaitingWelcome` is true, skip the early send -- the subscription is already in `engine.subscriptions` and will be sent when `welcome` is received in `onmessage`.
|
||||
|
||||
**Status: OPEN (BLOCKER)**
|
||||
|
||||
---
|
||||
|
||||
## Unregistered Flags
|
||||
|
||||
### UF-01 -- `__Host-` prefix with `path: "/api/marketplace/callback"` violates prefix spec
|
||||
|
||||
**File:** `src/app/api/marketplace/connect/route.ts:29,37`
|
||||
|
||||
The `__Host-` cookie prefix per RFC 6265bis requires `Path=/`. The implementation sets `path: "/api/marketplace/callback"`. Chromium-based browsers enforce this and will silently reject the `Set-Cookie` header when `__Host-` is combined with a non-root path. In practice this means on HTTPS deployments the PKCE cookies may not be set at all, breaking the OAuth flow entirely -- or the browser falls back to setting them without the prefix, losing the security guarantee.
|
||||
|
||||
This is a functional correctness issue as well as a security regression. Recommend changing `path` to `"/"` or switching the cookie name to `pkce_state` / `pkce_verifier` without the `__Host-` prefix (accepting the loss of the prefix guarantee).
|
||||
|
||||
**Not a declared threat -- flagged as unregistered surface. Does not count as BLOCKER per config, but should be fixed before HTTPS deployment.**
|
||||
|
||||
---
|
||||
|
||||
### UF-02 -- `src/app/api/camera/extract/route.ts` uses raw `fetch` against user-supplied URL
|
||||
|
||||
**File:** `src/app/api/camera/extract/route.ts:17,29`
|
||||
|
||||
This route accepts a user-supplied `url` query parameter and passes it directly to `fetch()` without going through `safeFetch`. Current code only executes the fetch if `targetUrl.includes("balticlivecam.com")`, which provides weak host filtering via substring match rather than proper hostname validation. This is outside the declared Phase 3 scope but represents new SSRF attack surface that was not mitigated. A crafted URL like `https://evil.com?x=balticlivecam.com` would pass the check.
|
||||
|
||||
**Not a declared threat -- flagged as unregistered surface.**
|
||||
|
||||
---
|
||||
|
||||
### UF-03 -- `src/app/api/camera/test/route.ts` uses raw `fetch` against user-supplied URL
|
||||
|
||||
**File:** `src/app/api/camera/test/route.ts:45,56,68` (confirmed by grep)
|
||||
|
||||
The test route uses raw `fetch` with a user-supplied URL. Its auth posture was not reviewed in this phase. Flagged for completeness.
|
||||
|
||||
**Not a declared threat -- flagged as unregistered surface.**
|
||||
|
||||
---
|
||||
|
||||
## Summary
|
||||
|
||||
| Metric | Count |
|
||||
|--------|-------|
|
||||
| Total threats | 14 |
|
||||
| CLOSED | 13 |
|
||||
| OPEN (BLOCKER) | 1 |
|
||||
| Unregistered flags | 3 |
|
||||
|
||||
**Phase 3 MUST NOT SHIP until T14 is resolved.**
|
||||
|
||||
The fix is mechanical: add an `awaitingWelcome` guard in the `public subscribe()` method before the `this.send()` call at `WsClient.ts:210`.
|
||||
@@ -0,0 +1,212 @@
|
||||
# ADR-001 Consolidation Plan: Dual-Issue Path to Decentralized Plugin Auth
|
||||
|
||||
## Context
|
||||
|
||||
ADR-001 (`docs/architecture/decisions/adr-0001-decentralized-plugin-auth-and-ssrf-mitigation.md`, still marked **Proposed**) defines a decentralized auth model for plugin data streams: Ed25519-signed, 5-minute, audience-bound JWT tickets issued by the Marketplace and verified offline by each Data Engine using JWKS.
|
||||
|
||||
The current state is a partial, incoherent implementation across three repos. A recent attempt to land the Data-Engine half landed broken, took production down, and was rolled back. This plan consolidates everything required so the next attempt is **once-and-done** with a feature-flagged dual-issue strategy — the existing HS256 marketplace-session token keeps working untouched while a new Ed25519 data-plane ticket system is built end-to-end and flipped on per-plugin.
|
||||
|
||||
**Scope:** all three deployables — Local App (this repo), Marketplace (`marketplace.worldwideview.dev`), Data Engine (`wwv-data-engine-public`).
|
||||
|
||||
**Honest framing on "once and done":** this plan delivers **zero-downtime** but is **4–5 sequenced deploys across 3 repos**, not literally one deploy. Compressing the steps is exactly what caused the previous outage. Sequenced + dormant-flagged is the safest path that meets the no-downtime intent.
|
||||
|
||||
---
|
||||
|
||||
## Current State (what we found)
|
||||
|
||||
### ✅ Already in place
|
||||
- **AES-256-GCM at rest** for credentials — `src/lib/auth/encryption.ts` (PBKDF2 100k, v1 versioning, nonce+salt in DB). Schema `MarketplaceCredential` at `prisma/schema.prisma:92-104`.
|
||||
- **PKCE initiation** — `src/app/api/marketplace/connect/route.ts` (openid-client v6, S256, `__Host-` cookies).
|
||||
- **PKCE callback** — `src/app/api/marketplace/callback/route.ts` (state check, encrypted persist). Tests at `src/app/api/marketplace/pkce.spec.ts`.
|
||||
- **JWT claims type contract** — `packages/wwv-plugin-sdk/src/auth-contracts.ts` (`PluginJwtClaims`, `WebSocketAuthMessage`).
|
||||
- **SSRF partial defenses** in the JSON proxy — `src/lib/security/ssrf.ts` (post-DNS private-IP block, pinned-IP agent, size/time limits) used by `src/app/api/camera/proxy/route.ts` and `stream/route.ts`.
|
||||
|
||||
### ⚠️ Half-finished / risky (must be resolved before any deploy)
|
||||
1. `src/lib/marketplace/marketplaceToken.ts` — HS256, 4h, hard-coded `aud`. **Acceptable as the marketplace-session bridge token only**; must NOT be used as a data-plane ticket. C1 enforces this via branded types (`MarketplaceSessionToken` vs `PluginTicket`) so the compiler refuses misuse.
|
||||
2. `src/app/api/marketplace/callback/route.ts:27-29` — currently calls a non-existent `/api/tickets/exchange` endpoint and casts `openid-client` config as `any`. A4 ships the correct endpoint as `/api/oauth/token`; C1 updates the callback URL and removes the cast. Suspected source of the previous deploy break.
|
||||
3. `src/lib/auth/encryption.ts:9` — silent fallback to a zeroed key if `ENCRYPTION_MASTER_KEY` env var unset. Must throw at startup.
|
||||
4. `src/app/api/camera/proxy/iframe/route.ts` — bypasses `safeFetch` entirely; raw `fetch` with default redirect-follow and no size cap.
|
||||
5. No host allowlist on any proxy route (ADR-001D constraint 1) — accepts any HTTPS host.
|
||||
6. `src/core/data/WsClient.ts:67-69` — sends `subscribe` immediately on `onopen`; no first-message auth, contract `WebSocketAuthMessage` is defined but unused.
|
||||
|
||||
### ❌ Missing entirely
|
||||
- **Ed25519 keypair** + **JWKS endpoint** on the Marketplace.
|
||||
- **Ticket-issuance endpoint** on the Marketplace (`POST /api/tickets/exchange` → returns 5-min EdDSA JWT for a named audience).
|
||||
- **JWT verification** on the Data Engine (`@fastify/jwt` + `get-jwks`, audience binding, unknown-`kid` re-fetch, fail-closed cold start).
|
||||
- **First-message auth handshake** on the Data Engine WebSocket (3s timeout, close code 4003, no re-auth, log redaction).
|
||||
- **Marketplace-side PKCE token endpoint** that the Local App callback expects.
|
||||
- **Origin / Host / TLS-state validation** on the Data Engine WS upgrade.
|
||||
- ADR doc still `Proposed`; never moved to `Accepted`.
|
||||
|
||||
---
|
||||
|
||||
## Strategy: Dual-Issue, Feature-Flagged, Coordinated Cutover
|
||||
|
||||
Two token systems live side by side. **Nothing existing is removed in this phase.**
|
||||
|
||||
| Token | Algo | Lifetime | Issued by | Verified by | Purpose |
|
||||
|---|---|---|---|---|---|
|
||||
| Marketplace-session (existing) | HS256 | 4h | Marketplace | Marketplace API only | UI login session. **Unchanged.** |
|
||||
| Plugin-ticket (new) | EdDSA / Ed25519 | 5 min | Marketplace | Each Data Engine via JWKS | Data-plane WebSocket auth. **New, flag-gated.** |
|
||||
|
||||
Canonical flag names used throughout this plan:
|
||||
- **Client (Local App), per-plugin opt-in:** `NEXT_PUBLIC_WWV_TICKET_AUTH_PLUGINS` (comma-separated plugin IDs).
|
||||
- **Engine (Data Engine), per-plugin enforcement:** `REQUIRE_TICKET_AUTH_PLUGINS` (comma-separated).
|
||||
- **Engine, global default-deny:** `REQUIRE_TICKET_AUTH` (boolean, default `false`).
|
||||
- **Engine, Origin allowlist enforcement:** `ENFORCE_ORIGIN_ALLOWLIST` (boolean, default `false`).
|
||||
- **Local App SSRF allowlist:** `PROXY_HOST_ALLOWLIST` (`*` sentinel, empty/unset = deny, or concrete list).
|
||||
|
||||
When all three engine flags are off, Data Engine accepts unauthenticated connections (today's behavior). When `REQUIRE_TICKET_AUTH_PLUGINS` includes a plugin, the client must send `{type:"auth", v:1, token}` first message and engine validates.
|
||||
|
||||
This means each repo can be deployed independently in the safe order below; the new code is dormant until the flag is flipped per-plugin.
|
||||
|
||||
---
|
||||
|
||||
## Workstreams
|
||||
|
||||
### A. Marketplace repo (separate codebase — produce a hand-off spec from this plan)
|
||||
Deliverables the Marketplace team must ship:
|
||||
1. **Ed25519 keypair generation + storage**, with overlap support (current + next `kid`).
|
||||
2. `GET /.well-known/jwks.json` — public keys array, `Cache-Control: public, max-age=300`.
|
||||
3. **Data-plane ticket exchange** — `POST /api/tickets/exchange` — body `{ api_key, audience, plugin_id }`; returns `{ token, expires_in: 300 }`. Claims per ADR-001B: `iss, sub, aud, exp, iat, jti, tier, scope`. Redis-backed `jti` issuance counter for rate-limiting; Postgres fallback per ADR failure-mode table.
|
||||
4. Library: `jose` for sign + JWKS publication.
|
||||
|
||||
### A4. Marketplace API-Key sub-spec (gating workstream — must complete BEFORE step 2)
|
||||
|
||||
Pulled out of Workstream A because it is not a one-endpoint change. The Marketplace does not currently have an "API Key" concept — today's PKCE callback stores the OAuth `access_token` directly. A4 invents the API-Key end-to-end:
|
||||
- New DB table for API Keys (device-bound, manually rotated per ADR-001C).
|
||||
- `POST /api/oauth/token` — the PKCE token endpoint consumed by `src/app/api/marketplace/callback/route.ts:27`. Renamed from `/api/tickets/exchange` to avoid path collision with A3.
|
||||
- API-Key issuance and rotation API.
|
||||
- Rotation UI in the Marketplace (per ADR-001C).
|
||||
- A4 is treated as its own workstream with its own sub-plan; do not bundle it into the A1–A3 deploy.
|
||||
|
||||
### B. Data Engine repo (`wwv-data-engine-public` — hand-off spec)
|
||||
|
||||
**SDK delivery mechanism (decide before B starts):** the Data Engine must consume the same `PluginJwtClaims` and `WebSocketAuthMessage` types that live in `packages/wwv-plugin-sdk` here. Pick one:
|
||||
- **(Recommended)** Publish `wwv-plugin-sdk` to a private npm registry (or GitHub Packages) with a SemVer tag; Data Engine pins `^x.y.z`.
|
||||
- Vendor a copy in Data Engine and add a CI check that diffs against the upstream SDK on push.
|
||||
- Git submodule pointing at a tagged commit.
|
||||
|
||||
Drift between repos = silent audience-binding mismatches. Pick one before any Workstream B code lands.
|
||||
|
||||
Deliverables:
|
||||
1. `@fastify/jwt` + `get-jwks` integration; LRU JWKS cache 5 min; unknown-`kid` triggers single background re-fetch then reject.
|
||||
2. **Fail-closed cold start** — if JWKS unreachable on boot, refuse all connections. **Gated by `REQUIRE_TICKET_AUTH || REQUIRE_TICKET_AUTH_PLUGINS !== "" || ENFORCE_ORIGIN_ALLOWLIST`** — when no ticket auth is active (the dormant-deploy state), JWKS unreachable is non-fatal at boot; engine boots, retries fetch in background. Today's engine has no Marketplace boot dependency, and the dormant deploy must preserve that.
|
||||
3. WS upgrade handler validates `Origin` (allowlist via env), `Host`, TLS state, expected tenant/plugin metadata. **Flag-gated by `ENFORCE_ORIGIN_ALLOWLIST` (default `false`)** so first deploy does not reject existing production clients. Flipped to `true` only after the allowlist has been populated and observed in logs (step 7).
|
||||
4. **First-message auth state machine** — connection state `AWAITING_AUTH`; 3s timer; reject any non-auth frame; close 4003 on failure; promote to `AUTHENTICATED` on success; no re-auth.
|
||||
5. Audience binding — reject if `aud !== process.env.ENGINE_ID`.
|
||||
6. Log redaction — JWT payloads never serialized to logs.
|
||||
7. Feature flag `REQUIRE_TICKET_AUTH` defaults `false`; production cuts over per-plugin. Separate from `ENFORCE_ORIGIN_ALLOWLIST` so the two protections can be rolled out independently.
|
||||
|
||||
### C. Local App (this repo — concrete file changes)
|
||||
|
||||
**C1. Cleanup & safety (must land first, no behavior change)**
|
||||
- `src/lib/auth/encryption.ts:9` — throw on missing **`ENCRYPTION_MASTER_KEY`** (correct var name; not `MASTER_KEY`) instead of zero fallback. **Pre-deploy gate:** verify `ENCRYPTION_MASTER_KEY` is set in every Coolify environment (local-self-host template, cloud, demo) and in `.env.example` before merging this change — otherwise next deploy fails on boot.
|
||||
- `src/app/api/marketplace/callback/route.ts:29` — replace `config as any` with proper `client.discovery()` once Marketplace publishes its discovery doc; until then, type the config explicitly.
|
||||
- **Type-level separation instead of runtime guard:** Introduce branded types in `packages/wwv-plugin-sdk/src/auth-contracts.ts`:
|
||||
- `type MarketplaceSessionToken = string & { __brand: "marketplace-session" }`
|
||||
- `type PluginTicket = string & { __brand: "plugin-ticket" }`
|
||||
- `marketplaceToken.ts` signs/returns `MarketplaceSessionToken`; new `ticketClient.ts` returns `PluginTicket`; `WsClient`'s auth message accepts only `PluginTicket`. Compiler enforces the separation — no fragile runtime detection.
|
||||
- Add doc comment to `marketplaceToken.ts`: "Marketplace UI session only — NOT a data-plane ticket."
|
||||
- Existing consumers ([src/lib/marketplace/auth.ts](src/lib/marketplace/auth.ts), [install-redirect/route.ts](src/app/api/marketplace/install-redirect/route.ts), [grant-token/route.ts](src/app/api/marketplace/grant-token/route.ts)) continue to receive `MarketplaceSessionToken` — no behavior change.
|
||||
|
||||
**C2. SSRF hardening (ADR-001D)**
|
||||
- Add `PROXY_HOST_ALLOWLIST` env var (comma-separated). Enforce in `src/lib/security/ssrf.ts` before scheme/IP checks. **Default behavior:**
|
||||
- `PROXY_HOST_ALLOWLIST="*"` → permissive (current behavior), logs a `WARN` per request naming the host so operators can populate the list from observed traffic. **Sentinel-based instead of relying on unset-vs-empty** because Coolify and similar PaaS UIs may send `""` for "unset."
|
||||
- `PROXY_HOST_ALLOWLIST=""` or unset → deny all (safe default).
|
||||
- `PROXY_HOST_ALLOWLIST="a.example,b.example"` → only those hosts allowed.
|
||||
Ship C2 with the var set to `*` in all environments; populate over a week of log observation; flip to a concrete allowlist in step 7c.
|
||||
- `src/app/api/camera/proxy/iframe/route.ts` — route through `safeFetch`; add 5 MB size cap; reject redirects to non-allowlisted hosts (don't follow by default).
|
||||
- Document the allowlist procedure in `.agents/context/environment-config.md`.
|
||||
|
||||
**C3. Ticket client (new, dormant behind flag)**
|
||||
- New module `src/lib/auth/ticketClient.ts`: given a `pluginId` and the encrypted API Key from `MarketplaceCredential`, POSTs to Marketplace `/api/tickets/exchange`, caches the 5-min JWT in memory keyed by `(pluginId, audience)`, refreshes at 4.5 min.
|
||||
- New hook `src/core/data/useTicket.ts` consumed by `WsClient`.
|
||||
|
||||
**C4. WebSocket first-message auth (client side)**
|
||||
- `src/core/data/WsClient.ts:67-69` — when `ticketAuth` enabled for plugin, on `onopen` send `WebSocketAuthMessage` (from `auth-contracts.ts`) *before* any subscribe; queue subscribes until server `ack`.
|
||||
- Add 3 s client-side auth timeout that closes and reconnects.
|
||||
|
||||
**C5. Feature flag**
|
||||
- `src/core/edition.ts` — new flag `ticketAuthEnabledForPlugin(pluginId): boolean`, sourced from `NEXT_PUBLIC_WWV_TICKET_AUTH_PLUGINS` (comma list) so we can enable one plugin at a time.
|
||||
|
||||
**C6. ADR status**
|
||||
- Move `docs/architecture/decisions/adr-0001-...md:4` from `Proposed` to `Accepted` once Workstreams A/B/C land in their repos but BEFORE any plugin is flag-flipped.
|
||||
|
||||
---
|
||||
|
||||
## Parallelization: what runs concurrently vs sequentially
|
||||
|
||||
**Code writing — fully parallel.** Three agents can work in three repos simultaneously with zero file conflicts:
|
||||
- Agent 1: Marketplace (`worldwideview-marketplace`, `feat/adr-001-marketplace`) — A1, A2, A3 fixes.
|
||||
- Agent 2: Data Engine (`wwv-data-engine`, `feat/adr-001-data-engine`) — B1-B5 fixes.
|
||||
- Agent 3: Local App (`worldwideview.feat-adr-001-local-app`, `feat/adr-001-local-app`) — C1, C2 first; then C3, C4, C5 once contract is confirmed.
|
||||
|
||||
The wire contract (POST body shape for `/api/auth/exchange`, JWT claim shape, WS first-message format) is already defined in `packages/wwv-plugin-sdk/src/auth-contracts.ts` and the existing Marketplace/Data Engine code — agents don't need to coordinate on it.
|
||||
|
||||
**Workstream A4 (Marketplace PKCE / API Key invention) can also run in parallel** with the other three, since it touches new files (`/api/oauth/token`, new Prisma model) and doesn't conflict with A1-A3. Treat it as a 4th parallel track.
|
||||
|
||||
**Deploys — must be sequenced** (this is the part that took down the previous attempt by compressing it). The order in the next section enforces that.
|
||||
|
||||
**Bottom line:** parallelize the *writing*, sequence the *shipping*.
|
||||
|
||||
## Deploy Order (zero-downtime sequenced choreography)
|
||||
|
||||
Steps 1–5 are individually deployable and dormant for the new ticket flow. **Step 1 introduces a hard `ENCRYPTION_MASTER_KEY` requirement** that the step-0 audit must confirm is satisfied — that is the riskiest item in the pre-ticket-cutover phase. Production behavior for ticket auth does not change until step 6.
|
||||
|
||||
0. **Pre-flight audit (before any code lands).** The previous failed deploy may have left debris. Audit and reconcile, producing an artifact at `docs/deploys/2026-MM-DD-adr-001-preflight.md` (use today's date) that records:
|
||||
- Coolify env vars on the Local App, Marketplace, and Data Engine services — list every `JWT_*`, `TICKET_*`, `JWKS_*`, `AUTH_*` var and decide keep/remove.
|
||||
- `wwv-data-engine-public` `main` branch — confirm the rolled-back state is clean (no half-merged `@fastify/jwt` wiring, no env-gated bypass middleware).
|
||||
- Any feature flags or dormant routes already in production from the prior attempt.
|
||||
- Confirm `ENCRYPTION_MASTER_KEY` is set on every environment (gate for C1).
|
||||
- Confirm decision on SDK delivery mechanism (gate for B).
|
||||
- Create `docs/feature-flags.md` listing all 5 flags introduced by this plan (`NEXT_PUBLIC_WWV_TICKET_AUTH_PLUGINS`, `REQUIRE_TICKET_AUTH`, `REQUIRE_TICKET_AUTH_PLUGINS`, `ENFORCE_ORIGIN_ALLOWLIST`, `PROXY_HOST_ALLOWLIST`) with: which repo, default value, what each setting means, and a per-environment table (dev/staging/prod) the operator keeps current. Drift between staging and prod is a known paper-cut; the doc is the single source of truth.
|
||||
- Confirm A4 sub-spec (Marketplace API-Key invention) has its own plan and is on track — A4 must ship before step 2.
|
||||
|
||||
1. **Local App** ships C1 + C2 (cleanup + SSRF). Pure hardening, no protocol change. Verify and deploy.
|
||||
2. **Marketplace** ships A1–A3 (Ed25519 keys, JWKS endpoint, data-plane ticket-exchange). **A4 must already be shipped** as a prerequisite (see Workstream A4 above) — confirmed in step 0. New endpoints only, no existing endpoint changes. Verify JWKS reachable.
|
||||
3. **Local App** ships C3 + C4 + C5 (ticket client, first-message auth, flag) with flag set to `""` (empty = nothing enabled). Dormant. Deploy.
|
||||
4. **Data Engine** ships B1–B7 with `REQUIRE_TICKET_AUTH=false` **and** `ENFORCE_ORIGIN_ALLOWLIST=false`. Both new verification paths exist but are dormant. Deploy.
|
||||
5. **Smoke test in staging** — flip flag for one synthetic plugin only; verify end-to-end ticket → WS auth → stream → 5-min refresh → revocation latency.
|
||||
6. **Cut over one real plugin at a time** by adding it to `NEXT_PUBLIC_WWV_TICKET_AUTH_PLUGINS` and the engine's `REQUIRE_TICKET_AUTH_PLUGINS`. Monitor each for 24h before adding the next.
|
||||
7. **Default-deny rollout — split into three independent steps with 24h soak between each** so attribution is clear if anything breaks:
|
||||
- **7a.** Set `REQUIRE_TICKET_AUTH=true` on the Data Engine. Soak 24h.
|
||||
- **7b.** Set `ENFORCE_ORIGIN_ALLOWLIST=true` on the Data Engine (after populating the Origin allowlist from observed connections). Soak 24h.
|
||||
- **7c.** Replace `PROXY_HOST_ALLOWLIST="*"` with the concrete observed list on the Local App. Soak 24h.
|
||||
Each step is independently revertable by flipping its single flag back.
|
||||
8. **Accept** the ADR; schedule HS256 marketplace-session token review as a follow-up (out of scope here).
|
||||
|
||||
**Re-verification rule (anti-dormant-code rot):** between steps 3 and 5, run the staging smoke test (step 5) **weekly** if the cutover is paused. Dormant feature-flagged code rots — catching it weekly in staging beats finding it broken on cutover day.
|
||||
|
||||
Rollback at any step: remove the plugin from the env list. Old path is still wired up because we never removed it.
|
||||
|
||||
---
|
||||
|
||||
## Critical Files (this repo)
|
||||
|
||||
- `src/lib/auth/encryption.ts` — fix silent fallback (C1)
|
||||
- `src/lib/security/ssrf.ts` — add host allowlist (C2)
|
||||
- `src/app/api/camera/proxy/iframe/route.ts` — route via safeFetch (C2)
|
||||
- `src/app/api/marketplace/callback/route.ts` — remove `as any` cast (C1)
|
||||
- `src/lib/marketplace/marketplaceToken.ts` — guard against data-plane misuse (C1)
|
||||
- `src/lib/auth/ticketClient.ts` — **new** (C3)
|
||||
- `src/core/data/WsClient.ts` — first-message auth (C4)
|
||||
- `src/core/edition.ts` — per-plugin flag accessor (C5)
|
||||
- `packages/wwv-plugin-sdk/src/auth-contracts.ts` — already has the types, reuse
|
||||
- `docs/architecture/decisions/adr-0001-...md` — status flip (C6)
|
||||
|
||||
---
|
||||
|
||||
## Verification
|
||||
|
||||
End-to-end (run in staging, gated by `NEXT_PUBLIC_WWV_TICKET_AUTH_PLUGINS=test-synthetic`):
|
||||
|
||||
1. `pnpm test` — Vitest suite green including new tests for `ticketClient` and `WsClient` first-message flow.
|
||||
2. `pnpm build` — no TS errors after removing the `as any` cast.
|
||||
3. Manual: with engine `REQUIRE_TICKET_AUTH_PLUGINS=test-synthetic`, connect WS without auth message → engine closes with 4003 within 3 s.
|
||||
4. Manual: valid ticket → stream flows; wait 4.5 min → client transparently refreshes; revoke API Key on Marketplace → next refresh fails, current stream finishes its 5-min window then disconnects (matches ADR revocation table).
|
||||
5. Stop Marketplace → Data Engine cold-start refuses connections (fail-closed); restart Marketplace → connections resume.
|
||||
6. SSRF: attempt `POST /api/camera/proxy` to a host not in `PROXY_HOST_ALLOWLIST` → 403. Attempt to a host resolving to 127.0.0.1 → 403.
|
||||
7. Encryption fallback: unset `ENCRYPTION_MASTER_KEY`, start app → process refuses to start.
|
||||
|
||||
Deploy gate: all of the above pass in staging before step 6 of the deploy order touches any production plugin.
|
||||
@@ -0,0 +1,264 @@
|
||||
# ADR-001 Workstream A: Marketplace Hardening (A1–A3)
|
||||
|
||||
## Context
|
||||
|
||||
The Marketplace already ships two stubbed JWT endpoints from a prior attempt:
|
||||
- `GET /api/auth/jwks` — Ed25519 JWKS publication
|
||||
- `POST /api/auth/exchange` — issues 5-min audience-bound EdDSA tickets
|
||||
|
||||
Both are functional but wrong in production-critical ways: the JWKS cache is set to 24h (mismatched against the 5-min ticket lifetime), the API-key check is a hardcoded string, and the JWT claims (`sub`, `aud`, `tier`, `scope`) are stubs.
|
||||
|
||||
ADR-001 (`C:\dev\worldwideview\docs\architecture\decisions\adr-0001-decentralized-plugin-auth-and-ssrf-mitigation.md`) makes this the foundation of decentralized plugin auth: each Data Engine verifies tickets offline via JWKS, with no Marketplace DB roundtrip per frame. A wrong cache TTL or missing `kid` silently breaks every consumer.
|
||||
|
||||
This plan delivers **A1 + A2 + A3 only** — the bounded hardening of the two existing endpoints, plus the minimum schema needed to back A3 with real DB lookups. **A4 (PKCE token endpoint + API-Key issuance UI) is deferred** to its own branch/PR per the master plan's explicit instruction: *"Treat it as its own workstream with its own sub-plan; do not bundle it into the A1–A3 deploy."*
|
||||
|
||||
A4 also depends on design decisions outside this scope (how a user authenticates to the Marketplace, whether there's a consent screen, how `openid-client` on the Local App expects the token response shaped) that should not be force-fit into a hardening pass.
|
||||
|
||||
---
|
||||
|
||||
## Decisions (with rationale)
|
||||
|
||||
### D1. Separate `User` table (vs. denormalize onto API key)
|
||||
- Per ADR-001B, `sub` is "the user's unique ID" and `tier` is subscription-scoped. These are identity facts, not credential facts. A user with two devices (two API keys) shares one tier.
|
||||
- Denormalizing tier onto each `MarketplaceApiKey` row creates multi-row update consistency problems on tier change.
|
||||
|
||||
### D2. SHA-256 for `keyHash` (vs. bcrypt per HANDOFF)
|
||||
- The HANDOFF says "bcrypt of the raw key," but bcrypt is non-deterministic — `WHERE keyHash = bcrypt(input)` is impossible. The exchange endpoint would have to load every row and `bcrypt.compare` each, which is O(n) per request.
|
||||
- API keys here are **32 bytes of CSPRNG output** (256 bits of entropy). Slow hashing is for low-entropy passwords; for high-entropy secrets, SHA-256 with constant-time compare is the standard (GitHub, AWS, Stripe all use deterministic hashes for API keys).
|
||||
- No new dependency. Uses `node:crypto` (already a Node built-in).
|
||||
|
||||
### D3. Defer A4 entirely
|
||||
- Master plan: A4 is its own workstream.
|
||||
- A4 is gated by product decisions (Marketplace auth/login, consent UI) that don't exist yet.
|
||||
- A1–A3 deliver real value independently — they make the existing JWT issuance pipeline production-correct.
|
||||
- The Local App's PKCE callback is already broken (calls `/api/tickets/exchange` which doesn't exist); deferring A4 doesn't regress anything.
|
||||
|
||||
### D4. Scope derivation from tier (not stored)
|
||||
- ADR-001B says `scope` is "specific entitlements." If stored separately from tier, the two can drift.
|
||||
- Derive at JWT issuance: `free → "plugins:read"`, `pro → "plugins:read plugins:write"`, `enterprise → "plugins:read plugins:write plugins:admin"`. Single function, easy to extend.
|
||||
|
||||
---
|
||||
|
||||
## Implementation
|
||||
|
||||
### A1. Fix JWKS cache TTL
|
||||
**File:** `src/app/api/auth/jwks/route.ts:26`
|
||||
|
||||
Change `max-age=86400, stale-while-revalidate=86400` → `max-age=300, stale-while-revalidate=60`.
|
||||
|
||||
Rationale: ticket lifetime is 5 min (300s) per ADR-001B. Cache TTL matching the ticket lifetime means a Data Engine can never have stale JWKS during a valid ticket's lifetime. `swr=60` lets engines tolerate brief Marketplace downtime — matches the ADR's "JWKS cache expires (Marketplace down) → grace period" failure mode row.
|
||||
|
||||
### A2. Ensure `kid` present in JWK
|
||||
**File:** `src/app/api/auth/jwks/route.ts`
|
||||
|
||||
Currently relies on the env-var JWK having a `kid` field, which the spread `{ ...privateJwk }` carries through. But there's no defensive check — if `MARKETPLACE_JWK_PRIVATE` was generated without `kid`, the endpoint silently publishes a key with no identifier, and `get-jwks` on the Data Engine can't cache it.
|
||||
|
||||
Fix: after parsing, throw if `privateJwk.kid` is falsy. Return 500 with a clear error log (`MARKETPLACE_JWK_PRIVATE is missing 'kid' field — regenerate per README`).
|
||||
|
||||
Also: ensure `alg: "EdDSA"` is present on the published JWK so JWKS consumers can pre-validate algorithm. The spread carries it through if set; add the same defensive check.
|
||||
|
||||
> **Pre-mortem mitigation (TIGER, medium):** this check is fail-closed — if the *current production* `MARKETPLACE_JWK_PRIVATE` lacks `kid`, this deploy turns "JWKS works without kid" into "JWKS 500s every Data Engine fetch." **Before merging**, audit the env var in every environment (local-self-host, cloud, demo):
|
||||
> ```
|
||||
> node -e "const j=JSON.parse(process.env.MARKETPLACE_JWK_PRIVATE);console.log('kid:',j.kid,'alg:',j.alg)"
|
||||
> ```
|
||||
> If any environment prints `kid: undefined`, regenerate the keypair per the HANDOFF README *before* this code reaches that environment.
|
||||
|
||||
### A3. Harden the token exchange endpoint
|
||||
|
||||
#### A3a. Schema additions
|
||||
**File:** `prisma/schema.prisma`
|
||||
|
||||
Add two models:
|
||||
|
||||
```prisma
|
||||
model User {
|
||||
id String @id @default(cuid())
|
||||
email String @unique
|
||||
tier String @default("free") // "free" | "pro" | "enterprise"
|
||||
createdAt DateTime @default(now())
|
||||
apiKeys MarketplaceApiKey[]
|
||||
}
|
||||
|
||||
model MarketplaceApiKey {
|
||||
id String @id @default(cuid())
|
||||
userId String
|
||||
keyHash String @unique // SHA-256 hex of raw key, used for O(1) lookup
|
||||
deviceId String?
|
||||
name String? // user-given label, e.g. "Home Server"
|
||||
createdAt DateTime @default(now())
|
||||
lastUsedAt DateTime?
|
||||
revokedAt DateTime?
|
||||
user User @relation(fields: [userId], references: [id])
|
||||
|
||||
@@index([userId])
|
||||
}
|
||||
```
|
||||
|
||||
Run `pnpm prisma migrate dev --name add_user_and_marketplace_api_key`.
|
||||
|
||||
Note: `MarketplaceApiKey` model is added here even though A4 (issuance) is deferred — A3's DB lookup needs the model to exist. A4 will add the *issuance path*; A3 only consumes the table.
|
||||
|
||||
#### A3b. Add a `scopeFor(tier)` helper
|
||||
**File (new):** `src/lib/auth/tierScope.ts`
|
||||
|
||||
```ts
|
||||
export function scopeFor(tier: string): string {
|
||||
switch (tier) {
|
||||
case "enterprise": return "plugins:read plugins:write plugins:admin";
|
||||
case "pro": return "plugins:read plugins:write";
|
||||
case "free":
|
||||
default: return "plugins:read";
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Single source of truth; A4 will also use this.
|
||||
|
||||
#### A3c. Add a key-hashing helper
|
||||
**File (new):** `src/lib/auth/apiKeyHash.ts`
|
||||
|
||||
```ts
|
||||
import { createHash, timingSafeEqual } from "node:crypto";
|
||||
|
||||
/** Deterministic SHA-256 hex of an API key. Use for DB lookup. */
|
||||
export function hashApiKey(rawKey: string): string {
|
||||
return createHash("sha256").update(rawKey, "utf8").digest("hex");
|
||||
}
|
||||
|
||||
/** Constant-time compare of two hex strings. */
|
||||
export function timingSafeEqualHex(a: string, b: string): boolean {
|
||||
if (a.length !== b.length) return false;
|
||||
return timingSafeEqual(Buffer.from(a, "hex"), Buffer.from(b, "hex"));
|
||||
}
|
||||
```
|
||||
|
||||
#### A3d. Rewrite the exchange endpoint
|
||||
**File:** `src/app/api/auth/exchange/route.ts`
|
||||
|
||||
- Parse body as `{ apiKey, audience?, plugin_id? }`.
|
||||
- Reject if `apiKey` missing (400).
|
||||
- Hash the apiKey via `hashApiKey()` and look up `prisma.marketplaceApiKey.findUnique({ where: { keyHash }, include: { user: true } })`.
|
||||
- If not found, or `revokedAt != null` → 401.
|
||||
- Update `lastUsedAt = new Date()` (fire-and-forget: `prisma.marketplaceApiKey.update(...).catch(err => console.warn("lastUsedAt update failed:", err.message))` — never await, never let it fail the request).
|
||||
- JWT claims:
|
||||
- `iss`: `"https://marketplace.worldwideview.dev"` (unchanged)
|
||||
- `sub`: `apiKeyRecord.userId` (was: `"user-id-stub"`)
|
||||
- `aud`: `audience ?? "wwv-data-engine"` (default for backwards-compat per HANDOFF)
|
||||
- `tier`: `apiKeyRecord.user.tier` (was: `"pro"`)
|
||||
- `scope`: `scopeFor(apiKeyRecord.user.tier)` (was: `"plugins:read"`)
|
||||
- `exp`, `iat`, `nbf`, `jti`: unchanged
|
||||
- Header `kid`: unchanged
|
||||
- Return `{ token }` as before.
|
||||
|
||||
#### A3e. Update tests
|
||||
**File:** `src/app/api/auth/exchange/route.spec.ts`
|
||||
|
||||
- Mock `@/lib/prisma` with `vi.mock`. Provide a fake `prisma.marketplaceApiKey.findUnique` that returns a fixture user/key for one specific hashed key, and `null` otherwise.
|
||||
- Test: invalid key → 401.
|
||||
- Test: valid key → 200, JWT contains `sub` matching user id, `aud` matching request body, `tier`/`scope` matching user fixture.
|
||||
- Test: revoked key (revokedAt set) → 401.
|
||||
- Test: `aud` defaults to `"wwv-data-engine"` when `audience` omitted from body.
|
||||
- Keep the existing claim-shape assertions.
|
||||
|
||||
**File:** `src/app/api/auth/jwks/route.spec.ts`
|
||||
- Add: when env JWK has no `kid` → 500.
|
||||
- Add: response has `Cache-Control` with `max-age=300`.
|
||||
|
||||
### Seed data
|
||||
**File:** `prisma/seed.ts`
|
||||
|
||||
Add a test user + API key (only run in dev/test) so the exchange endpoint can be exercised by `curl`:
|
||||
|
||||
```ts
|
||||
// Add to existing seed
|
||||
const testUser = await prisma.user.upsert({
|
||||
where: { email: "[email protected]" },
|
||||
update: {},
|
||||
create: { email: "[email protected]", tier: "pro" }
|
||||
});
|
||||
await prisma.marketplaceApiKey.upsert({
|
||||
where: { keyHash: hashApiKey("dev-key-do-not-use-in-prod") },
|
||||
update: {},
|
||||
create: {
|
||||
userId: testUser.id,
|
||||
keyHash: hashApiKey("dev-key-do-not-use-in-prod"),
|
||||
name: "dev seed key"
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
Raw key `dev-key-do-not-use-in-prod` is committed intentionally — it only works against a local dev DB seeded with it.
|
||||
|
||||
---
|
||||
|
||||
## Critical files
|
||||
|
||||
| File | Change | Task |
|
||||
|---|---|---|
|
||||
| `src/app/api/auth/jwks/route.ts` | Cache header + kid defensive check | A1, A2 |
|
||||
| `src/app/api/auth/jwks/route.spec.ts` | New tests for kid + cache | A1, A2 |
|
||||
| `prisma/schema.prisma` | Add User + MarketplaceApiKey models | A3a |
|
||||
| `src/lib/auth/tierScope.ts` | **NEW** — scope derivation | A3b |
|
||||
| `src/lib/auth/apiKeyHash.ts` | **NEW** — SHA-256 + constant-time compare | A3c |
|
||||
| `src/app/api/auth/exchange/route.ts` | Real DB lookup, real claims | A3d |
|
||||
| `src/app/api/auth/exchange/route.spec.ts` | Prisma-mocked tests | A3e |
|
||||
| `prisma/seed.ts` | Dev seed user + key | (dev only) |
|
||||
|
||||
Existing utilities reused:
|
||||
- `src/lib/prisma.ts` — singleton Prisma client.
|
||||
- `jose` (already installed) — JWT signing.
|
||||
- `node:crypto` — SHA-256, timing-safe compare.
|
||||
|
||||
---
|
||||
|
||||
## Verification
|
||||
|
||||
1. `pnpm prisma migrate dev` — migration applies cleanly to a fresh DB.
|
||||
2. `pnpm test` — vitest suite green: new + updated exchange tests, jwks tests.
|
||||
3. `pnpm lint && pnpm build` — no TS errors.
|
||||
4. Manual end-to-end (dev):
|
||||
- `pnpm prisma db seed` — seeds dev user + key.
|
||||
- `curl http://localhost:3000/api/auth/jwks` — returns `{ keys: [{ kty:"OKP", crv:"Ed25519", x, kid, alg:"EdDSA" }] }`, no `d`, `Cache-Control: public, max-age=300, stale-while-revalidate=60`.
|
||||
- `curl -X POST http://localhost:3000/api/auth/exchange -d '{"apiKey":"dev-key-do-not-use-in-prod","audience":"wwv-aviation-engine","plugin_id":"aviation"}' -H 'Content-Type: application/json'` — returns `{ token }`.
|
||||
- Decode the JWT at jwt.io: `iss === "https://marketplace.worldwideview.dev"`, `sub` is the seeded user id, `aud === "wwv-aviation-engine"`, `tier === "pro"`, `scope === "plugins:read plugins:write"`, `exp - iat === 300`, header has `kid`.
|
||||
- Same curl with `apiKey: "valid-key-for-testing"` (the old stub) → 401.
|
||||
- Same curl with `apiKey` omitted → 400.
|
||||
|
||||
---
|
||||
|
||||
## Deployment checklist (pre-mortem mitigations)
|
||||
|
||||
1. **Pre-deploy env audit** — before this code reaches any environment, run:
|
||||
```
|
||||
node -e "const j=JSON.parse(process.env.MARKETPLACE_JWK_PRIVATE);console.log('kid:',j.kid,'alg:',j.alg)"
|
||||
```
|
||||
Both must be non-null. If `kid` is missing, regenerate the keypair (the HANDOFF README has the Node script). Do this in every environment (local-self-host, cloud, demo) before merging.
|
||||
|
||||
2. **Production migration** — the deploy pipeline must run `pnpm prisma migrate deploy` (not `migrate dev`) on boot before the app starts. Verify this is wired into the Coolify start command or Dockerfile CMD. The new `User` and `MarketplaceApiKey` tables must exist before any request reaches the exchange endpoint.
|
||||
|
||||
3. **Empty-table gap** — after A3 deploys and until A4 ships, the exchange endpoint requires a real `MarketplaceApiKey` row to issue a JWT. There are no such rows in production until A4's issuance path lands. This is acceptable because: (a) the Local App's callback is already broken today (`/api/tickets/exchange` 404s), so no real traffic is hitting this endpoint, and (b) the `dev-key-do-not-use-in-prod` seed entry gives a working dev/staging test path through the real code. Document this gap in the PR description so the next person isn't confused by a blank table.
|
||||
|
||||
---
|
||||
|
||||
## Out of scope (explicit deferrals)
|
||||
|
||||
- **A4 — PKCE token endpoint, OAuth authorize page, API-Key issuance UI.** Its own workstream. The `MarketplaceApiKey` model is added in A3 so A4 can plug straight in without a schema migration.
|
||||
- **Key rotation overlap** (multi-key JWKS array). The JWKS endpoint already returns an array of one key; multi-key rotation is a separate concern.
|
||||
|
||||
---
|
||||
|
||||
## Risk Mitigations (Pre-Mortem)
|
||||
|
||||
**Pre-mortem run:** 2026-05-21 | Mode: quick | Tigers: 3 | Elephants: 1
|
||||
|
||||
### Tigers addressed
|
||||
1. **Production migration path unclear** (medium) — Mitigation: Deployment checklist item 2 above. Plan explicitly requires `prisma migrate deploy` step.
|
||||
2. **`kid` defensive check fails-closed on deploy** (medium) — Mitigation: Deployment checklist item 1 above. Mandatory pre-deploy env audit.
|
||||
3. **Fire-and-forget `lastUsedAt` unhandled rejection** (low) — Mitigation: Added `.catch(warn)` to A3d spec.
|
||||
|
||||
### Elephant addressed
|
||||
- **No user creation path until A4** — Mitigation: dev seed provides a working test path; prod gap documented in deployment checklist item 3. Acceptable because the endpoint has zero real traffic today.
|
||||
|
||||
### Accepted risks (none — all addressed)
|
||||
- **Redis-backed `jti` counter / rate limiting.** Per ADR-001 failure-mode table, this is part of issuance hardening — not bundled here.
|
||||
- **`/api/tickets/exchange` legacy path.** The Local App currently points there but it doesn't exist. Renaming the callback URL is a Local App change (workstream C1), not Marketplace.
|
||||
@@ -0,0 +1,173 @@
|
||||
# ADR-001 Production Auth Rollout — Two-Track Strategy
|
||||
|
||||
## Context
|
||||
|
||||
PR #9 (`wwv-data-engine`) merged + deployed. Auth is bypassed (`WWV_SKIP_WS_AUTH=true`).
|
||||
`WWV_SKIP_WS_AUTH` lives on the **engine** — flipping it affects every app connecting
|
||||
to that engine (demo, local, future cloud). The demo has anonymous visitors with no
|
||||
user session. It needs a **service credential** (machine-to-machine API key) so
|
||||
`/api/auth/ticket` can issue JWTs on behalf of visitors with no session.
|
||||
|
||||
ADR-003 (Supabase identity) is not yet implemented and blocks the full PKCE user
|
||||
flow. It must not block the demo deployment.
|
||||
|
||||
**Strategy:**
|
||||
- **Track A (demo, immediate):** Seed a service credential into production DBs → flip
|
||||
auth on → zero user-facing change. No PKCE needed.
|
||||
- **Track B (local/self-hosted, medium-term):** Implement the PKCE OAuth server on
|
||||
the marketplace using admin-password auth (no Supabase). When ADR-003 lands,
|
||||
replace the password check with Supabase session check — same OAuth interface,
|
||||
no client changes.
|
||||
|
||||
---
|
||||
|
||||
## Track A — Demo Service Credential (Production)
|
||||
|
||||
### Why this works
|
||||
**`src/core/edition.ts` line 70:** `export const isAuthEnabled: boolean = !isDemo;`
|
||||
|
||||
`isAuthEnabled = false` in demo edition → `/api/auth/ticket` skips the session
|
||||
gate entirely and calls `getTicket()` directly. The admin's "special login page"
|
||||
uses `WWV_DEMO_ADMIN_SECRET` — a completely separate mechanism unrelated to the
|
||||
ticket flow. Every anonymous visitor can call `/api/auth/ticket` and get a JWT,
|
||||
provided `MarketplaceCredential { tenantId: "local" }` exists in the demo DB.
|
||||
|
||||
Also confirmed: `ticketAuthEnabledForPlugin()` parses `NEXT_PUBLIC_WWV_TICKET_AUTH_PLUGINS`
|
||||
as CSV. The current `"\"\""` bug in Coolify makes it parse to no valid IDs → all
|
||||
plugins skip ticket auth → they connect unauthenticated → `WWV_SKIP_WS_AUTH=true`
|
||||
lets them in. Fixing the env var + adding the credential + flipping auth is the
|
||||
complete transition.
|
||||
|
||||
### Prerequisites (Coolify → `worldwideview-demo` → Environment)
|
||||
```
|
||||
ENCRYPTION_MASTER_KEY=<generate: node -e "console.log(require('crypto').randomBytes(32).toString('base64'))">
|
||||
MARKETPLACE_URL=https://marketplace.worldwideview.dev
|
||||
```
|
||||
Set these before running the seed script. The master key is used to encrypt the
|
||||
credential at seed time and decrypt it at runtime.
|
||||
|
||||
### Step A1 — Write seed script
|
||||
|
||||
**File:** `local-scripts/seed-demo-credential.mjs`
|
||||
|
||||
One idempotent run does:
|
||||
1. Connects to marketplace SQLite on the server (SSH + direct file access or
|
||||
Prisma with `DATABASE_URL=file:<path>`)
|
||||
- Upserts `User { email: "[email protected]", tier: "pro" }`
|
||||
- Generates raw API key: `crypto.randomBytes(32).toString('hex')`
|
||||
- SHA256-hashes it → upserts `MarketplaceApiKey { userId, keyHash, revokedAt: null }`
|
||||
|
||||
2. Connects to demo PostgreSQL
|
||||
- AES-256-GCM encrypts the raw API key using `ENCRYPTION_MASTER_KEY`
|
||||
(matching the format in `src/lib/auth/encryption.ts`:
|
||||
`pbkdf2Sync(key, salt, 100000, 32, 'sha256')` → cipher → `base64(ct).base64(tag)`)
|
||||
- Upserts `marketplace_credentials { tenantId: "local", version:"v1", salt, nonce, ciphertext }`
|
||||
|
||||
3. Prints `[seed] ✅ Demo service credential installed`
|
||||
|
||||
### Step A2 — Fix env var + rebuild demo
|
||||
Coolify → `worldwideview-demo` → Environment:
|
||||
- `NEXT_PUBLIC_WWV_TICKET_AUTH_PLUGINS` → `aviation,maritime` (remove literal quotes)
|
||||
- Trigger **rebuild** (build-time env var — restart alone doesn't pick it up)
|
||||
|
||||
### Step A3 — Verify ticket route
|
||||
```bash
|
||||
curl https://<demo-fqdn>/api/auth/ticket?pluginId=aviation
|
||||
# expect: { "token": "eyJ..." }
|
||||
```
|
||||
- 500 → `ENCRYPTION_MASTER_KEY` mismatch or credential not seeded
|
||||
- 200 with no `token` field → `ticketClient` returned wrong shape
|
||||
- 401 → `isAuthEnabled` is true (shouldn't happen in demo edition — check `NEXT_PUBLIC_WWV_EDITION=demo`)
|
||||
|
||||
### Step A4 — Flip auth on engine
|
||||
Coolify → `wwv-engine-stack` → Environment → `WWV_SKIP_WS_AUTH=false` → Deploy.
|
||||
|
||||
### Step A5 — Smoke test
|
||||
```bash
|
||||
node local-scripts/local-smoke-test.mjs # pointed at production URLs
|
||||
# Step 1: JWKS ✅ Step 2: Exchange ✅ Step 3: WS welcome ✅
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Track B — PKCE OAuth Server on Marketplace (Local/Self-Hosted)
|
||||
|
||||
Implements the missing `GET /oauth/authorize` (consent page) and
|
||||
`POST /api/oauth/token` (code exchange) on the marketplace. Uses admin-password
|
||||
auth for now — Supabase replaces the password check when ADR-003 lands. Same
|
||||
OAuth interface; no client-side changes needed during that migration.
|
||||
|
||||
### Files to create/modify in `c:/dev/worldwideview-marketplace/`
|
||||
|
||||
**`prisma/schema.prisma`** — add:
|
||||
```prisma
|
||||
model OAuthCode {
|
||||
id String @id @default(cuid())
|
||||
code String @unique
|
||||
userId String
|
||||
user User @relation(fields: [userId], references: [id])
|
||||
codeChallenge String
|
||||
redirectUri String
|
||||
clientId String
|
||||
scope String
|
||||
state String
|
||||
expiresAt DateTime
|
||||
usedAt DateTime?
|
||||
|
||||
@@index([code])
|
||||
}
|
||||
```
|
||||
Add `oauthCodes OAuthCode[]` to `User`. Run `npx prisma db push` (SQLite, local).
|
||||
|
||||
**`src/app/oauth/authorize/page.tsx`** — consent UI:
|
||||
- Reads URL params: `client_id`, `code_challenge`, `state`, `redirect_uri`, `scope`
|
||||
- Renders form: "Local App is requesting access to your data. Enter your admin password."
|
||||
- Stores params in hidden fields, POSTs to `/api/oauth/authorize`
|
||||
|
||||
**`src/app/api/oauth/authorize/route.ts`** (POST):
|
||||
- Validates `password === process.env.ADMIN_PASSWORD`
|
||||
- Finds or creates `User { email: "local@marketplace", tier: "pro" }`
|
||||
- Creates `OAuthCode { code: randomBytes(32).hex, expiresAt: now+10min, ... }`
|
||||
- Redirects to `redirectUri?code=<code>&state=<state>`
|
||||
- **ADR-003 migration point:** swap password check for `supabase.auth.getUser()` session check
|
||||
|
||||
**`src/app/api/oauth/token/route.ts`** (POST, `application/x-www-form-urlencoded`):
|
||||
- Parses `{ grant_type, code, code_verifier, client_id, redirect_uri }`
|
||||
- Finds `OAuthCode`; verifies not expired, not used, clientId + redirectUri match
|
||||
- PKCE: `createHash('sha256').update(code_verifier).digest('base64url') === codeChallenge`
|
||||
- Marks `usedAt = now` (replay protection)
|
||||
- Generates raw API key: `randomBytes(32).hex`
|
||||
- SHA256-hash → creates `MarketplaceApiKey { userId, keyHash }`
|
||||
- Returns `{ access_token: rawApiKey, token_type: "bearer" }`
|
||||
|
||||
**Note:** `connect/route.ts` in local app redirects to `/oauth/authorize` (no `/api/` prefix)
|
||||
— the consent page is at that path. The POST handler is at `/api/oauth/authorize`.
|
||||
|
||||
### Local app env (`.env.local`):
|
||||
```
|
||||
NEXT_PUBLIC_WWV_MARKETPLACE_URL=http://localhost:3001
|
||||
ENCRYPTION_MASTER_KEY=<any-32+-char-string>
|
||||
```
|
||||
|
||||
### Verification (Track B)
|
||||
1. Start all 3 services locally
|
||||
2. Browser: `http://localhost:3000/api/marketplace/connect`
|
||||
→ redirects to `http://localhost:3001/oauth/authorize?...`
|
||||
→ enter admin password → redirects back to local app
|
||||
3. `GET http://localhost:3000/api/auth/ticket?pluginId=aviation` → `{ token: "eyJ..." }`
|
||||
4. Check WebSocket in devtools → `{ type: "welcome" }`
|
||||
|
||||
---
|
||||
|
||||
## ADR-003 Migration Path (future, no client changes needed)
|
||||
When Supabase Auth is wired into the marketplace:
|
||||
- `/api/oauth/authorize` replaces `password === ADMIN_PASSWORD` with `supabase.auth.getUser()`
|
||||
- If no session → redirect to `worldwideview.dev/login?redirect_to=marketplace.../oauth/authorize?...`
|
||||
- Everything else stays identical — same code format, same token endpoint, same local app callback
|
||||
|
||||
---
|
||||
|
||||
## Order of Execution
|
||||
1. **Track A first** (demo service credential + auth flip) — unblocks production
|
||||
2. **Track B in parallel or after** (PKCE for local instances) — enables proper self-hosted UX
|
||||
3. **ADR-003 later** — migrates marketplace auth internals without touching clients
|
||||
@@ -0,0 +1,874 @@
|
||||
# WorldWideView Auth Rollout — ADR-001 + ADR-003
|
||||
|
||||
> **For agentic workers:** REQUIRED SUB-SKILL: use `superpowers:executing-plans` to implement
|
||||
> this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
|
||||
|
||||
**Goal:** Get ADR-001 (decentralized plugin auth) and ADR-003 (shared ecosystem identity)
|
||||
into production with the least possible downtime. `/cloud` plan registration and billing
|
||||
are deferred.
|
||||
|
||||
**Architecture:** One shared Supabase project is the identity store. `worldwideview.dev`
|
||||
(the `worldwideview-web` repo) becomes the SSR auth host; a parent-domain cookie
|
||||
(`.worldwideview.dev`) is inherited by every subdomain. The Marketplace becomes a PKCE
|
||||
OAuth server on top of that session. The Local App is the PKCE client. The Data Engine
|
||||
validates 5-minute JWTs on its WebSocket.
|
||||
|
||||
**Tech Stack:** Next.js 16 App Router, `@supabase/ssr`, Supabase Auth, Ed25519 JWTs
|
||||
(`jose`), Prisma, Docker + Coolify.
|
||||
|
||||
---
|
||||
|
||||
## Northstar Sequence (the map)
|
||||
|
||||
Build everything locally on `wwv.local` HTTPS first, then deploy production one repo at a
|
||||
time in this dependency order. Each deploy is independently revertible.
|
||||
|
||||
1. **Phase 0** — Provision Supabase + local HTTPS dev (human setup — see checklist below).
|
||||
2. **Phase 1** — `worldwideview-web` becomes the SSR auth host. ← **detailed below**
|
||||
3. **Phase 2** — Marketplace consumes the session + adds the PKCE OAuth server.
|
||||
4. **Phase 3** — Merge the ADR-001 Local App worktree.
|
||||
5. **Phase 4** — Data Engine WebSocket first-message JWT auth (report-only → enforcing).
|
||||
6. **Phase 5** — Final cutover, link the nav, update docs, mark ADRs Accepted.
|
||||
|
||||
Phases 2–5 are detailed once Phase 1 lands and Assumption #2 (below) is confirmed.
|
||||
|
||||
---
|
||||
|
||||
## Phase 0 — Human Setup Checklist (do this while Phase 1 code is written)
|
||||
|
||||
These cannot be automated — they need accounts, browsers, admin rights, or a DNS panel.
|
||||
|
||||
- [ ] **0.1 Create the Supabase project.** supabase.com → New project. Pick a region close
|
||||
to the Coolify host. Save the DB password. Copy three values: Project URL, `anon` public
|
||||
key, `service_role` secret key.
|
||||
- [ ] **0.2 Enable auth providers** (Supabase dashboard → Authentication → Providers):
|
||||
- Email: enable, "Confirm email" ON.
|
||||
- Google: create an OAuth Client in Google Cloud Console (APIs & Services → Credentials →
|
||||
OAuth client ID → Web app). Authorized redirect URI:
|
||||
`https://<project-ref>.supabase.co/auth/v1/callback`. Paste Client ID + Secret into
|
||||
Supabase.
|
||||
- GitHub: GitHub → Settings → Developer settings → OAuth Apps → New. Authorization
|
||||
callback URL: `https://<project-ref>.supabase.co/auth/v1/callback`. Paste Client ID +
|
||||
Secret into Supabase.
|
||||
- [ ] **0.3 Set URL configuration** (Authentication → URL Configuration):
|
||||
- Site URL: `https://worldwideview.dev`
|
||||
- Redirect URLs (add all): `https://worldwideview.dev/**`,
|
||||
`https://*.worldwideview.dev/**`, `https://wwv.local/**`, `https://*.wwv.local/**`
|
||||
- [ ] **0.4 Install mkcert** (one-time, per dev machine). PowerShell as admin:
|
||||
`choco install mkcert` then `mkcert -install`.
|
||||
- [ ] **0.5 Generate the local TLS cert.** In `c:\dev\wwv`:
|
||||
`mkcert "*.wwv.local" wwv.local` — produces a `.pem` cert + key pair.
|
||||
- [ ] **0.6 Edit the hosts file** (admin). Add to `C:\Windows\System32\drivers\etc\hosts`:
|
||||
`127.0.0.1 wwv.local marketplace.wwv.local app.wwv.local`
|
||||
- [ ] **0.7 Confirm production DNS.** `worldwideview.dev`, `marketplace.worldwideview.dev`,
|
||||
`app.worldwideview.dev` (and a `*.worldwideview.dev` wildcard) must point at the Coolify
|
||||
host. Check the DNS provider; add records if missing.
|
||||
- [ ] **0.8 Decide Assumption #2** — Marketplace keeps SQLite, or migrates to Supabase
|
||||
Postgres? (See "Assumptions" at the end. This unblocks the Phase 2 detailed plan.)
|
||||
- [ ] **0.9 Hand me the Supabase values** (or paste them yourself) so they can go into the
|
||||
local `.env` files and the Coolify env vars — never committed to git. Needed:
|
||||
`NEXT_PUBLIC_SUPABASE_URL`, `NEXT_PUBLIC_SUPABASE_ANON_KEY`, `SUPABASE_SERVICE_ROLE_KEY`.
|
||||
- [ ] **0.10 (Optional) Resend SMTP** — only if launching with magic-link login. Create a
|
||||
Resend account, verify a sending domain, paste SMTP creds into Supabase → Project
|
||||
Settings → Auth → SMTP. Skip if launching with email+password + OAuth only.
|
||||
|
||||
---
|
||||
|
||||
# Phase 1 Implementation Plan — `worldwideview-web` Auth Host
|
||||
|
||||
**Repo:** `c:\dev\wwv\worldwideview-web`
|
||||
**Outcome:** `worldwideview.dev` serves the landing site (static) plus working SSR
|
||||
`/login`, `/signup`, `/accounts`, and `/api/auth/callback`, with sessions written to a
|
||||
parent-domain cookie. The container runs as Node, not Nginx.
|
||||
|
||||
### File Structure
|
||||
|
||||
| File | Responsibility |
|
||||
|---|---|
|
||||
| `next.config.ts` | Drop static export, switch to `standalone`, add headers |
|
||||
| `vitest.config.ts` (new) | Unit test runner config |
|
||||
| `src/lib/supabase/cookieOptions.ts` (new) | Pure helper: resolve cookie domain from env |
|
||||
| `src/lib/supabase/cookieOptions.test.ts` (new) | Unit tests for the helper |
|
||||
| `src/lib/supabase/client.ts` | Browser client via `@supabase/ssr` |
|
||||
| `src/lib/supabase/server.ts` (new) | Server client via `@supabase/ssr` |
|
||||
| `middleware.ts` (new) | Refresh the session on every request |
|
||||
| `src/app/api/health/route.ts` (new) | Health endpoint for Coolify deploy gating |
|
||||
| `src/app/login/page.tsx` | SSR login: email+password + OAuth |
|
||||
| `src/app/login/actions.ts` (new) | Server action: password sign-in |
|
||||
| `src/app/login/oauth-buttons.tsx` (new) | Client component: Google/GitHub buttons |
|
||||
| `src/app/signup/page.tsx` (new) | SSR signup |
|
||||
| `src/app/signup/actions.ts` (new) | Server action: account creation |
|
||||
| `src/app/accounts/page.tsx` (new) | Account view + logout |
|
||||
| `src/app/accounts/actions.ts` (new) | Server action: sign out |
|
||||
| `src/app/api/auth/callback/route.ts` (new) | OAuth code → session exchange |
|
||||
| `Dockerfile` | Node standalone runtime instead of Nginx |
|
||||
| `docker-compose.yml` | Port mapping for the Node container |
|
||||
| `.env.local` (new, not committed) | Local Supabase + cookie-domain vars |
|
||||
|
||||
---
|
||||
|
||||
### Task 1: Add dependencies and the test runner
|
||||
|
||||
**Files:** Modify `package.json`; Create `vitest.config.ts`; Create `.env.local`.
|
||||
|
||||
- [ ] **Step 1: Install `@supabase/ssr`.**
|
||||
|
||||
Run in `c:\dev\wwv\worldwideview-web`:
|
||||
```bash
|
||||
pnpm add @supabase/ssr
|
||||
```
|
||||
Expected: `@supabase/ssr` appears under `dependencies` in `package.json`.
|
||||
|
||||
- [ ] **Step 2: Add a `test` script.** In `package.json` `scripts`, add:
|
||||
```json
|
||||
"test": "vitest run"
|
||||
```
|
||||
|
||||
- [ ] **Step 3: Create `vitest.config.ts`.**
|
||||
```ts
|
||||
import { defineConfig } from 'vitest/config'
|
||||
import react from '@vitejs/plugin-react'
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [react()],
|
||||
test: {
|
||||
environment: 'jsdom',
|
||||
globals: true,
|
||||
},
|
||||
})
|
||||
```
|
||||
|
||||
- [ ] **Step 4: Create `.env.local`** (NOT committed — confirm it is in `.gitignore`):
|
||||
```
|
||||
NEXT_PUBLIC_SUPABASE_URL=<from Phase 0.1>
|
||||
NEXT_PUBLIC_SUPABASE_ANON_KEY=<from Phase 0.1>
|
||||
NEXT_PUBLIC_WWV_COOKIE_DOMAIN=.wwv.local
|
||||
```
|
||||
|
||||
- [ ] **Step 5: Verify the `@supabase/ssr` API.** Use context7 (`resolve-library-id`
|
||||
→ `query-docs` for `@supabase/ssr` "Next.js App Router server client middleware") to
|
||||
confirm `createServerClient` / `createBrowserClient` signatures match the installed
|
||||
version before writing Tasks 3–4. The `getAll`/`setAll` cookie pattern below is the
|
||||
stable pattern; adjust only if the installed version differs.
|
||||
|
||||
- [ ] **Step 6: Commit.**
|
||||
```bash
|
||||
git add package.json pnpm-lock.yaml vitest.config.ts
|
||||
git commit -m "chore: add @supabase/ssr and vitest runner"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Task 2: Cookie-domain resolver helper (TDD)
|
||||
|
||||
The cookie `domain` must be `.worldwideview.dev` in production, `.wwv.local` in dev, and
|
||||
**unset** when running on plain `localhost` (browsers reject a `domain` on `localhost`).
|
||||
This is the one piece of pure logic worth a unit test.
|
||||
|
||||
**Files:** Create `src/lib/supabase/cookieOptions.ts`,
|
||||
`src/lib/supabase/cookieOptions.test.ts`.
|
||||
|
||||
- [ ] **Step 1: Write the failing test.** `src/lib/supabase/cookieOptions.test.ts`:
|
||||
```ts
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { resolveCookieDomain } from './cookieOptions'
|
||||
|
||||
describe('resolveCookieDomain', () => {
|
||||
it('returns undefined when nothing is configured', () => {
|
||||
expect(resolveCookieDomain(undefined)).toBeUndefined()
|
||||
})
|
||||
it('returns undefined for an empty string', () => {
|
||||
expect(resolveCookieDomain('')).toBeUndefined()
|
||||
})
|
||||
it('returns the configured domain', () => {
|
||||
expect(resolveCookieDomain('.worldwideview.dev')).toBe('.worldwideview.dev')
|
||||
})
|
||||
it('trims surrounding whitespace', () => {
|
||||
expect(resolveCookieDomain(' .wwv.local ')).toBe('.wwv.local')
|
||||
})
|
||||
})
|
||||
```
|
||||
|
||||
- [ ] **Step 2: Run the test, confirm it fails.**
|
||||
Run: `pnpm test`
|
||||
Expected: FAIL — `resolveCookieDomain` is not exported / file not found.
|
||||
|
||||
- [ ] **Step 3: Implement `src/lib/supabase/cookieOptions.ts`.**
|
||||
```ts
|
||||
export function resolveCookieDomain(raw: string | undefined): string | undefined {
|
||||
const trimmed = raw?.trim()
|
||||
return trimmed ? trimmed : undefined
|
||||
}
|
||||
|
||||
export function buildCookieOptions() {
|
||||
return {
|
||||
domain: resolveCookieDomain(process.env.NEXT_PUBLIC_WWV_COOKIE_DOMAIN),
|
||||
path: '/',
|
||||
sameSite: 'lax' as const,
|
||||
secure: true,
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
- [ ] **Step 4: Run the test, confirm it passes.**
|
||||
Run: `pnpm test`
|
||||
Expected: PASS — 4 passing.
|
||||
|
||||
- [ ] **Step 5: Commit.**
|
||||
```bash
|
||||
git add src/lib/supabase/cookieOptions.ts src/lib/supabase/cookieOptions.test.ts
|
||||
git commit -m "feat: add cookie-domain resolver for cross-subdomain sessions"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Task 3: Supabase browser + server clients
|
||||
|
||||
**Files:** Modify `src/lib/supabase/client.ts`; Create `src/lib/supabase/server.ts`.
|
||||
|
||||
- [ ] **Step 1: Rewrite `src/lib/supabase/client.ts`** (browser client — now a factory):
|
||||
```ts
|
||||
import { createBrowserClient } from '@supabase/ssr'
|
||||
import { buildCookieOptions } from './cookieOptions'
|
||||
|
||||
export function createClient() {
|
||||
return createBrowserClient(
|
||||
process.env.NEXT_PUBLIC_SUPABASE_URL!,
|
||||
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
|
||||
{ cookieOptions: buildCookieOptions() },
|
||||
)
|
||||
}
|
||||
```
|
||||
|
||||
- [ ] **Step 2: Create `src/lib/supabase/server.ts`** (server client):
|
||||
```ts
|
||||
import { createServerClient } from '@supabase/ssr'
|
||||
import { cookies } from 'next/headers'
|
||||
import { buildCookieOptions } from './cookieOptions'
|
||||
|
||||
export async function createClient() {
|
||||
const cookieStore = await cookies()
|
||||
return createServerClient(
|
||||
process.env.NEXT_PUBLIC_SUPABASE_URL!,
|
||||
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
|
||||
{
|
||||
cookieOptions: buildCookieOptions(),
|
||||
cookies: {
|
||||
getAll() {
|
||||
return cookieStore.getAll()
|
||||
},
|
||||
setAll(cookiesToSet) {
|
||||
try {
|
||||
cookiesToSet.forEach(({ name, value, options }) =>
|
||||
cookieStore.set(name, value, options),
|
||||
)
|
||||
} catch {
|
||||
// Called from a Server Component — middleware refreshes instead.
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
)
|
||||
}
|
||||
```
|
||||
|
||||
- [ ] **Step 3: Migrate existing importers of the old `supabase` singleton.**
|
||||
Run: `grep -rn "lib/supabase/client" src/` — every hit that did `import { supabase }`
|
||||
must change to `import { createClient }` + `const supabase = createClient()`. The `hub/`
|
||||
page is a known importer. Update each.
|
||||
|
||||
- [ ] **Step 4: Verify the build typechecks.**
|
||||
Run: `pnpm build`
|
||||
Expected: build proceeds past type-checking (it may still fail later on `output: export`
|
||||
+ middleware — that is fixed in Task 5; a clean `tsc` pass here is the goal).
|
||||
|
||||
- [ ] **Step 5: Commit.**
|
||||
```bash
|
||||
git add src/lib/supabase/client.ts src/lib/supabase/server.ts src/app/hub
|
||||
git commit -m "feat: add @supabase/ssr browser and server clients"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Task 4: Session-refresh middleware
|
||||
|
||||
**Files:** Create `middleware.ts` (repo root, sibling of `src/`).
|
||||
|
||||
- [ ] **Step 1: Create `middleware.ts`.**
|
||||
```ts
|
||||
import { createServerClient } from '@supabase/ssr'
|
||||
import { NextResponse, type NextRequest } from 'next/server'
|
||||
import { buildCookieOptions } from './src/lib/supabase/cookieOptions'
|
||||
|
||||
export async function middleware(request: NextRequest) {
|
||||
let response = NextResponse.next({ request })
|
||||
|
||||
const supabase = createServerClient(
|
||||
process.env.NEXT_PUBLIC_SUPABASE_URL!,
|
||||
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
|
||||
{
|
||||
cookieOptions: buildCookieOptions(),
|
||||
cookies: {
|
||||
getAll() {
|
||||
return request.cookies.getAll()
|
||||
},
|
||||
setAll(cookiesToSet) {
|
||||
cookiesToSet.forEach(({ name, value }) =>
|
||||
request.cookies.set(name, value),
|
||||
)
|
||||
response = NextResponse.next({ request })
|
||||
cookiesToSet.forEach(({ name, value, options }) =>
|
||||
response.cookies.set(name, value, options),
|
||||
)
|
||||
},
|
||||
},
|
||||
},
|
||||
)
|
||||
|
||||
// Refreshes the session cookie if expired. Do NOT add logic between
|
||||
// createServerClient and getUser().
|
||||
await supabase.auth.getUser()
|
||||
return response
|
||||
}
|
||||
|
||||
export const config = {
|
||||
matcher: ['/((?!_next/static|_next/image|favicon.ico|.*\\.(?:svg|png|jpg|jpeg|gif|webp)$).*)'],
|
||||
}
|
||||
```
|
||||
|
||||
- [ ] **Step 2: Verify it compiles.**
|
||||
Run: `pnpm build`
|
||||
Expected: no type errors from `middleware.ts`.
|
||||
|
||||
- [ ] **Step 3: Commit.**
|
||||
```bash
|
||||
git add middleware.ts
|
||||
git commit -m "feat: add session-refresh middleware"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Task 5: Convert `next.config.ts` from static export to SSR
|
||||
|
||||
**Files:** Modify `next.config.ts`.
|
||||
|
||||
- [ ] **Step 1: Replace `next.config.ts` entirely.**
|
||||
```ts
|
||||
import type { NextConfig } from "next";
|
||||
|
||||
const nextConfig: NextConfig = {
|
||||
output: "standalone",
|
||||
images: {
|
||||
unoptimized: true,
|
||||
},
|
||||
async headers() {
|
||||
return [
|
||||
{
|
||||
source: "/:path*",
|
||||
headers: [
|
||||
{ key: "X-Content-Type-Options", value: "nosniff" },
|
||||
{ key: "X-Frame-Options", value: "DENY" },
|
||||
{ key: "Referrer-Policy", value: "strict-origin-when-cross-origin" },
|
||||
],
|
||||
},
|
||||
];
|
||||
},
|
||||
};
|
||||
|
||||
export default nextConfig;
|
||||
```
|
||||
Note: any custom headers currently in `nginx.conf` should be folded into the `headers()`
|
||||
array. Keep CSP out for now unless `nginx.conf` already had one — an over-strict CSP
|
||||
silently breaks Supabase XHR calls.
|
||||
|
||||
- [ ] **Step 2: Build and confirm SSR mode.**
|
||||
Run: `pnpm build`
|
||||
Expected: build output lists routes as a mix of `○ (Static)` and `ƒ (Dynamic)`; auth
|
||||
routes appear as Dynamic. No `out/` directory is produced; `.next/standalone` is.
|
||||
|
||||
- [ ] **Step 3: Commit.**
|
||||
```bash
|
||||
git add next.config.ts
|
||||
git commit -m "feat: switch worldwideview-web from static export to standalone SSR"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Task 6: Health endpoint
|
||||
|
||||
**Files:** Create `src/app/api/health/route.ts`.
|
||||
|
||||
- [ ] **Step 1: Create the route.**
|
||||
```ts
|
||||
import { NextResponse } from 'next/server'
|
||||
|
||||
export const dynamic = 'force-dynamic'
|
||||
|
||||
export function GET() {
|
||||
return NextResponse.json({ status: 'ok' })
|
||||
}
|
||||
```
|
||||
|
||||
- [ ] **Step 2: Verify.**
|
||||
Run: `pnpm build && pnpm start` then in another shell: `curl -i http://localhost:3000/api/health`
|
||||
Expected: `200 OK`, body `{"status":"ok"}`.
|
||||
|
||||
- [ ] **Step 3: Commit.**
|
||||
```bash
|
||||
git add src/app/api/health/route.ts
|
||||
git commit -m "feat: add health endpoint for deploy gating"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Task 7: Login page (email+password + OAuth)
|
||||
|
||||
**Files:** Modify `src/app/login/page.tsx`; Create `src/app/login/actions.ts`,
|
||||
`src/app/login/oauth-buttons.tsx`.
|
||||
|
||||
- [ ] **Step 1: Create `src/app/login/actions.ts`.**
|
||||
```ts
|
||||
'use server'
|
||||
|
||||
import { redirect } from 'next/navigation'
|
||||
import { createClient } from '../../lib/supabase/server'
|
||||
|
||||
export async function signInWithPassword(formData: FormData) {
|
||||
const email = String(formData.get('email') ?? '')
|
||||
const password = String(formData.get('password') ?? '')
|
||||
const next = String(formData.get('next') ?? '/accounts')
|
||||
|
||||
const supabase = await createClient()
|
||||
const { error } = await supabase.auth.signInWithPassword({ email, password })
|
||||
|
||||
if (error) {
|
||||
redirect(`/login?error=${encodeURIComponent(error.message)}&next=${encodeURIComponent(next)}`)
|
||||
}
|
||||
redirect(next)
|
||||
}
|
||||
```
|
||||
|
||||
- [ ] **Step 2: Create `src/app/login/oauth-buttons.tsx`.**
|
||||
```tsx
|
||||
'use client'
|
||||
|
||||
import { createClient } from '../../lib/supabase/client'
|
||||
import styles from '../hub/hub.module.css'
|
||||
|
||||
export function OAuthButtons({ next }: { next: string }) {
|
||||
const signIn = async (provider: 'google' | 'github') => {
|
||||
const supabase = createClient()
|
||||
await supabase.auth.signInWithOAuth({
|
||||
provider,
|
||||
options: {
|
||||
redirectTo: `${window.location.origin}/api/auth/callback?next=${encodeURIComponent(next)}`,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
return (
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 'var(--space-sm)' }}>
|
||||
<button className={styles.submitButton} onClick={() => signIn('google')} type="button">
|
||||
Continue with Google
|
||||
</button>
|
||||
<button className={styles.submitButton} onClick={() => signIn('github')} type="button">
|
||||
Continue with GitHub
|
||||
</button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
```
|
||||
|
||||
- [ ] **Step 3: Rewrite `src/app/login/page.tsx`** as a server component:
|
||||
```tsx
|
||||
import { signInWithPassword } from './actions'
|
||||
import { OAuthButtons } from './oauth-buttons'
|
||||
import styles from '../hub/hub.module.css'
|
||||
|
||||
export default async function LoginPage({
|
||||
searchParams,
|
||||
}: {
|
||||
searchParams: Promise<{ error?: string; next?: string }>
|
||||
}) {
|
||||
const { error, next = '/accounts' } = await searchParams
|
||||
|
||||
return (
|
||||
<div className={styles.hubContainer}>
|
||||
<div className={styles.glassCard} style={{ maxWidth: '400px', marginTop: '10vh' }}>
|
||||
<h1 className={styles.title}>Welcome Back</h1>
|
||||
<p style={{ textAlign: 'center', marginBottom: 'var(--space-lg)', color: 'var(--text-secondary)' }}>
|
||||
Sign in to your WorldWideView account
|
||||
</p>
|
||||
|
||||
<form action={signInWithPassword}>
|
||||
<input type="hidden" name="next" value={next} />
|
||||
<input className={styles.inputField} type="email" name="email"
|
||||
placeholder="Email address" required />
|
||||
<input className={styles.inputField} type="password" name="password"
|
||||
placeholder="Password" required />
|
||||
<button className={styles.submitButton} type="submit">Sign In</button>
|
||||
</form>
|
||||
|
||||
<div style={{ textAlign: 'center', margin: 'var(--space-md) 0', color: 'var(--text-secondary)' }}>
|
||||
or
|
||||
</div>
|
||||
<OAuthButtons next={next} />
|
||||
|
||||
{error && (
|
||||
<p style={{ marginTop: 'var(--space-md)', textAlign: 'center', fontSize: '0.9rem',
|
||||
color: 'var(--color-accent)' }}>
|
||||
{error}
|
||||
</p>
|
||||
)}
|
||||
|
||||
<p style={{ marginTop: 'var(--space-md)', textAlign: 'center', fontSize: '0.9rem' }}>
|
||||
No account? <a href={`/signup?next=${encodeURIComponent(next)}`}>Create one</a>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
```
|
||||
|
||||
- [ ] **Step 4: Verify.**
|
||||
Run: `pnpm build`
|
||||
Expected: `/login` builds as a Dynamic route, no type errors.
|
||||
|
||||
- [ ] **Step 5: Commit.**
|
||||
```bash
|
||||
git add src/app/login
|
||||
git commit -m "feat: SSR login with email/password and OAuth"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Task 8: Signup page
|
||||
|
||||
**Files:** Create `src/app/signup/page.tsx`, `src/app/signup/actions.ts`.
|
||||
|
||||
- [ ] **Step 1: Create `src/app/signup/actions.ts`.**
|
||||
```ts
|
||||
'use server'
|
||||
|
||||
import { redirect } from 'next/navigation'
|
||||
import { createClient } from '../../lib/supabase/server'
|
||||
|
||||
export async function signUp(formData: FormData) {
|
||||
const email = String(formData.get('email') ?? '')
|
||||
const password = String(formData.get('password') ?? '')
|
||||
const next = String(formData.get('next') ?? '/accounts')
|
||||
|
||||
const supabase = await createClient()
|
||||
const { error } = await supabase.auth.signUp({
|
||||
email,
|
||||
password,
|
||||
options: { emailRedirectTo: `${process.env.NEXT_PUBLIC_SITE_URL ?? ''}/api/auth/callback?next=${encodeURIComponent(next)}` },
|
||||
})
|
||||
|
||||
if (error) {
|
||||
redirect(`/signup?error=${encodeURIComponent(error.message)}&next=${encodeURIComponent(next)}`)
|
||||
}
|
||||
redirect(`/login?message=${encodeURIComponent('Check your email to confirm your account.')}&next=${encodeURIComponent(next)}`)
|
||||
}
|
||||
```
|
||||
Note: add `NEXT_PUBLIC_SITE_URL` to `.env.local` (`https://wwv.local`) and to Coolify
|
||||
(`https://worldwideview.dev`).
|
||||
|
||||
- [ ] **Step 2: Create `src/app/signup/page.tsx`.**
|
||||
```tsx
|
||||
import { signUp } from './actions'
|
||||
import styles from '../hub/hub.module.css'
|
||||
|
||||
export default async function SignupPage({
|
||||
searchParams,
|
||||
}: {
|
||||
searchParams: Promise<{ error?: string; next?: string }>
|
||||
}) {
|
||||
const { error, next = '/accounts' } = await searchParams
|
||||
|
||||
return (
|
||||
<div className={styles.hubContainer}>
|
||||
<div className={styles.glassCard} style={{ maxWidth: '400px', marginTop: '10vh' }}>
|
||||
<h1 className={styles.title}>Create Account</h1>
|
||||
<form action={signUp}>
|
||||
<input type="hidden" name="next" value={next} />
|
||||
<input className={styles.inputField} type="email" name="email"
|
||||
placeholder="Email address" required />
|
||||
<input className={styles.inputField} type="password" name="password"
|
||||
placeholder="Password (8+ characters)" minLength={8} required />
|
||||
<button className={styles.submitButton} type="submit">Sign Up</button>
|
||||
</form>
|
||||
{error && (
|
||||
<p style={{ marginTop: 'var(--space-md)', textAlign: 'center', fontSize: '0.9rem',
|
||||
color: 'var(--color-accent)' }}>
|
||||
{error}
|
||||
</p>
|
||||
)}
|
||||
<p style={{ marginTop: 'var(--space-md)', textAlign: 'center', fontSize: '0.9rem' }}>
|
||||
Already have an account? <a href={`/login?next=${encodeURIComponent(next)}`}>Sign in</a>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
```
|
||||
|
||||
- [ ] **Step 3: Verify.** Run: `pnpm build` — `/signup` builds as Dynamic.
|
||||
|
||||
- [ ] **Step 4: Commit.**
|
||||
```bash
|
||||
git add src/app/signup
|
||||
git commit -m "feat: SSR signup page"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Task 9: OAuth callback route
|
||||
|
||||
**Files:** Create `src/app/api/auth/callback/route.ts`.
|
||||
|
||||
- [ ] **Step 1: Create the route.**
|
||||
```ts
|
||||
import { NextResponse } from 'next/server'
|
||||
import { createClient } from '../../../../lib/supabase/server'
|
||||
|
||||
export async function GET(request: Request) {
|
||||
const { searchParams, origin } = new URL(request.url)
|
||||
const code = searchParams.get('code')
|
||||
const next = searchParams.get('next') ?? '/accounts'
|
||||
|
||||
if (code) {
|
||||
const supabase = await createClient()
|
||||
const { error } = await supabase.auth.exchangeCodeForSession(code)
|
||||
if (!error) {
|
||||
return NextResponse.redirect(`${origin}${next}`)
|
||||
}
|
||||
}
|
||||
return NextResponse.redirect(`${origin}/login?error=${encodeURIComponent('Authentication failed')}`)
|
||||
}
|
||||
```
|
||||
|
||||
- [ ] **Step 2: Verify.** Run: `pnpm build` — route compiles.
|
||||
|
||||
- [ ] **Step 3: Commit.**
|
||||
```bash
|
||||
git add src/app/api/auth/callback/route.ts
|
||||
git commit -m "feat: OAuth callback route for code-to-session exchange"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Task 10: Accounts page + logout
|
||||
|
||||
**Files:** Create `src/app/accounts/page.tsx`, `src/app/accounts/actions.ts`.
|
||||
|
||||
- [ ] **Step 1: Create `src/app/accounts/actions.ts`.**
|
||||
```ts
|
||||
'use server'
|
||||
|
||||
import { redirect } from 'next/navigation'
|
||||
import { createClient } from '../../lib/supabase/server'
|
||||
|
||||
export async function signOut() {
|
||||
const supabase = await createClient()
|
||||
await supabase.auth.signOut()
|
||||
redirect('/login')
|
||||
}
|
||||
```
|
||||
|
||||
- [ ] **Step 2: Create `src/app/accounts/page.tsx`** (guards unauthenticated users):
|
||||
```tsx
|
||||
import { redirect } from 'next/navigation'
|
||||
import { createClient } from '../../lib/supabase/server'
|
||||
import { signOut } from './actions'
|
||||
import styles from '../hub/hub.module.css'
|
||||
|
||||
export default async function AccountsPage() {
|
||||
const supabase = await createClient()
|
||||
const { data: { user } } = await supabase.auth.getUser()
|
||||
|
||||
if (!user) {
|
||||
redirect('/login?next=/accounts')
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={styles.hubContainer}>
|
||||
<div className={styles.glassCard} style={{ maxWidth: '480px', marginTop: '10vh' }}>
|
||||
<h1 className={styles.title}>Your Account</h1>
|
||||
<p style={{ textAlign: 'center', color: 'var(--text-secondary)' }}>{user.email}</p>
|
||||
<form action={signOut}>
|
||||
<button className={styles.submitButton} type="submit">Sign Out</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
```
|
||||
|
||||
- [ ] **Step 3: Verify.** Run: `pnpm build` — `/accounts` builds as Dynamic.
|
||||
|
||||
- [ ] **Step 4: Commit.**
|
||||
```bash
|
||||
git add src/app/accounts
|
||||
git commit -m "feat: account page with parent-domain logout"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Task 11: Dockerfile → Node standalone runtime
|
||||
|
||||
**Files:** Modify `Dockerfile`; verify `.dockerignore`; modify `docker-compose.yml`.
|
||||
|
||||
- [ ] **Step 1: Replace `Dockerfile` entirely.**
|
||||
```dockerfile
|
||||
# Stage 1: Build
|
||||
FROM node:22-alpine AS builder
|
||||
WORKDIR /app
|
||||
RUN corepack enable pnpm
|
||||
COPY package.json pnpm-lock.yaml* ./
|
||||
RUN pnpm i --frozen-lockfile
|
||||
COPY . .
|
||||
|
||||
# NEXT_PUBLIC_* vars are inlined at build time — must be present as build args.
|
||||
ARG NEXT_PUBLIC_SUPABASE_URL
|
||||
ARG NEXT_PUBLIC_SUPABASE_ANON_KEY
|
||||
ARG NEXT_PUBLIC_WWV_COOKIE_DOMAIN
|
||||
ARG NEXT_PUBLIC_SITE_URL
|
||||
ENV NEXT_PUBLIC_SUPABASE_URL=$NEXT_PUBLIC_SUPABASE_URL
|
||||
ENV NEXT_PUBLIC_SUPABASE_ANON_KEY=$NEXT_PUBLIC_SUPABASE_ANON_KEY
|
||||
ENV NEXT_PUBLIC_WWV_COOKIE_DOMAIN=$NEXT_PUBLIC_WWV_COOKIE_DOMAIN
|
||||
ENV NEXT_PUBLIC_SITE_URL=$NEXT_PUBLIC_SITE_URL
|
||||
|
||||
RUN pnpm run build
|
||||
|
||||
# Stage 2: Runtime
|
||||
FROM node:22-alpine AS runner
|
||||
WORKDIR /app
|
||||
ENV NODE_ENV=production
|
||||
RUN addgroup --system --gid 1001 nodejs \
|
||||
&& adduser --system --uid 1001 nextjs
|
||||
|
||||
COPY --from=builder /app/public ./public
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
||||
|
||||
USER nextjs
|
||||
EXPOSE 3000
|
||||
ENV PORT=3000 HOSTNAME=0.0.0.0
|
||||
CMD ["node", "server.js"]
|
||||
```
|
||||
|
||||
- [ ] **Step 2: Confirm `.dockerignore` excludes `node_modules`, `.next`, `out`.**
|
||||
If missing, create `.dockerignore` with: `node_modules`, `.next`, `out`, `.git`.
|
||||
|
||||
- [ ] **Step 3: Update `docker-compose.yml`** so the web service maps a host port to
|
||||
container `3000` (was Nginx `80`), e.g. `ports: - "3001:3000"`, and passes the four
|
||||
`NEXT_PUBLIC_*` build args.
|
||||
|
||||
- [ ] **Step 4: Build the image locally.**
|
||||
Run: `docker build -t wwv-web-test .`
|
||||
Expected: build completes; the final image runs `node server.js`.
|
||||
|
||||
- [ ] **Step 5: Commit.**
|
||||
```bash
|
||||
git add Dockerfile .dockerignore docker-compose.yml
|
||||
git commit -m "feat: run worldwideview-web as a Node standalone container"
|
||||
```
|
||||
Note: `nginx.conf` is now unused — delete it in Phase 5 cleanup once production is verified.
|
||||
|
||||
---
|
||||
|
||||
### Task 12: Bump version
|
||||
|
||||
**Files:** Modify `package.json`.
|
||||
|
||||
- [ ] **Step 1:** Bump `version` `0.5.0` → `0.6.0` (a feature release — new auth surface).
|
||||
- [ ] **Step 2: Commit.**
|
||||
```bash
|
||||
git add package.json
|
||||
git commit -m "chore: bump version to 0.6.0"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Phase 1 Verification
|
||||
|
||||
**Local (on `wwv.local` HTTPS — requires Phase 0.4–0.6 done):**
|
||||
1. Run the dev server bound to `wwv.local` over HTTPS (via the mkcert cert or a local TLS
|
||||
proxy). Open `https://wwv.local/signup`.
|
||||
2. Create an account → confirm the email → land back authenticated.
|
||||
3. Sign out, then `https://wwv.local/login` with email+password → reach `/accounts`.
|
||||
4. In DevTools → Application → Cookies: the Supabase `sb-*` cookies have
|
||||
`Domain = .wwv.local`.
|
||||
5. Test Google and GitHub buttons → provider → `/api/auth/callback` → `/accounts`.
|
||||
6. `https://wwv.local/accounts` while logged out → redirect to `/login?next=/accounts`.
|
||||
7. Sign out → cookies cleared on `.wwv.local`.
|
||||
8. `curl -k https://wwv.local/api/health` → `{"status":"ok"}`.
|
||||
9. Marketing pages (`/`, `/about`, `/docs`) still load and are statically generated.
|
||||
|
||||
**Production deploy (the one downtime-sensitive cutover):**
|
||||
1. Push the branch, open a PR, run `/pr-review`.
|
||||
2. In Coolify: update the `worldwideview-web` app — new Dockerfile build, set the four
|
||||
`NEXT_PUBLIC_*` build args + runtime env vars, set the health check to `/api/health`.
|
||||
3. **Safest:** deploy first to a temporary domain (`web-next.worldwideview.dev`), smoke-test
|
||||
the full flow, then repoint `worldwideview.dev` (blue-green). Otherwise rely on Coolify's
|
||||
health-check-gated deploy so traffic only switches after `/api/health` passes.
|
||||
4. After cutover: smoke-test `worldwideview.dev` landing + `/login` + `/signup`.
|
||||
|
||||
---
|
||||
|
||||
## Assumptions / Open Questions
|
||||
|
||||
1. **No Supabase project exists yet** — Phase 0 creates one.
|
||||
2. **Marketplace keeps SQLite (Option A)** — recommended: the Marketplace consumes the
|
||||
Supabase *session* for identity but keeps plugin/API-key data in SQLite. If you want a
|
||||
full SQLite → Supabase-Postgres migration instead, Phase 2 is much larger. **This is the
|
||||
one decision that changes scope — please confirm (Phase 0.8).**
|
||||
3. **`/cloud` + billing deferred** — `/accounts` is minimal (profile + logout), no Stripe.
|
||||
4. **API-key management UI lives in the Marketplace** (ADR-001C wording), not in `/accounts`.
|
||||
5. **`SigningKey` rotation table** treated as a fast-follow, not a launch blocker.
|
||||
6. **The ADR-001 worktree branch needs consolidation** before merge (messy branch name,
|
||||
uncommitted changes) — handled in Phase 3.
|
||||
7. **`hub.module.css` is reused** for auth page styling to avoid new CSS scope. If you want
|
||||
dedicated auth styling, that is an easy add but not assumed here.
|
||||
8. **No Playwright in `worldwideview-web`** — Phase 1 verification is browser-manual. Adding
|
||||
a Playwright E2E suite is a reasonable but separate follow-up.
|
||||
|
||||
---
|
||||
|
||||
## Phase 1 — Implemented & Verified (2026-05-22)
|
||||
|
||||
All 12 implementation tasks done. `pnpm test` 16/16 green; `pnpm build` green (marketing
|
||||
pages Static, the 5 auth routes Dynamic, middleware active). `.env.local` verified against
|
||||
the live Supabase project `kvlnzjtcstnaqkpqrquf` — URL + publishable key match. The new
|
||||
API-key system is used throughout (`NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY`); `getClaims()`
|
||||
for session checks.
|
||||
|
||||
### Discovered at commit time: pre-existing uncommitted work (NOT Phase 1)
|
||||
|
||||
The `worldwideview-web` working tree already held a separate, coherent change —
|
||||
**"consolidate docs off the `docs.` subdomain back onto `/docs`"**:
|
||||
|
||||
- `src/proxy.ts` — **deleted** (was the `docs.` subdomain rewrite middleware; used Next 16's
|
||||
`proxy.ts` convention with `export function proxy`)
|
||||
- `src/app/docs/layout.tsx` — dropped the `NEXT_PUBLIC_IS_DOCS_SUBDOMAIN` branching
|
||||
- `src/components/Footer.tsx` — docs links `docs.worldwideview.dev` → `/docs`
|
||||
- `vercel.json` — removed the docs-subdomain redirects (now `{}`)
|
||||
- `.vscode/settings.json` — new untracked file
|
||||
|
||||
This is unrelated to the auth host. **Decision (user, 2026-05-22): commit the
|
||||
docs-consolidation work first as its own commit, then Phase 1.**
|
||||
|
||||
### Finalized commit sequence (branch `feat/auth-host` off `main`)
|
||||
|
||||
1. **Commit 1 — docs consolidation.** Stage only: `src/proxy.ts` (deletion),
|
||||
`src/app/docs/layout.tsx`, `src/components/Footer.tsx`, `vercel.json`. Message:
|
||||
`refactor(docs): serve docs from /docs instead of the docs. subdomain`.
|
||||
2. **Rename** Phase 1's root `middleware.ts` → `src/proxy.ts` (`export function proxy`).
|
||||
Clean now — Commit 1 removed the old `src/proxy.ts`, so Commit 2 just adds the new auth
|
||||
one. Matches the repo's Next-16 `proxy.ts` convention.
|
||||
3. **Commit 2 — Phase 1.** Version bump `0.5.0 → 0.6.0`; stage all Phase 1 files. Message:
|
||||
`feat: add SSR auth host with shared Supabase identity (ADR-003)`.
|
||||
4. Push `feat/auth-host`, open the PR (remote: `github.com/silvertakana/worldwideview-web`).
|
||||
|
||||
`.vscode/settings.json` (stray untracked file) is left out of both commits.
|
||||
@@ -0,0 +1,306 @@
|
||||
# Plan: Marketplace Authentication (Supabase Auth — Shared Identity)
|
||||
|
||||
## Context
|
||||
|
||||
The Marketplace (`marketplace.worldwideview.dev`, repo: `c:/dev/worldwideview-marketplace`) and the Cloud App (`app.worldwideview.dev`) share one identity ecosystem. A user who creates an account on the Marketplace can use that same account to access the Cloud App, and vice versa — no second signup required. This is called **Federated Identity / Single Sign-On (SSO)** and is the same model used by GitHub (one account → GitHub + GitHub Marketplace + GitHub Actions), Atlassian (one account → Jira + Confluence + Marketplace), and Stripe (one account → Dashboard + Stripe Apps).
|
||||
|
||||
The Marketplace has no database yet, so Supabase is the right choice: one Supabase project serves as the **shared identity store** for all WorldWideView products. Both the Marketplace and the Cloud App point at the same Supabase project URL — the same `auth.users` table — so a user is one entity across the entire ecosystem.
|
||||
|
||||
The Marketplace also acts as the **OAuth 2.0 Authorization Server** in the ADR-001 PKCE flow — when a Local App user clicks "Connect to Marketplace," they are redirected here to authorize, and the Marketplace issues a short-lived code that the Local App exchanges for an API Key.
|
||||
|
||||
> **⚠️ Rule conflict to resolve:** `.agents/rules/cloud-auth-architecture.md` currently says `app.worldwideview.dev` owns all login UI and the Marketplace redirects there. This plan reverses that — **Marketplace is the identity source**, and the Cloud App will defer to it. That rule file must be updated after this plan is approved.
|
||||
|
||||
---
|
||||
|
||||
## Decision: Shared Supabase Auth + Supabase Postgres
|
||||
|
||||
**Why:**
|
||||
- **One user table for the whole ecosystem** — `auth.users` is shared. A user created on Marketplace is immediately valid on Cloud App. No sync job, no duplication.
|
||||
- No database to spin up — Supabase project gives you Postgres + Auth in one dashboard click
|
||||
- Google OAuth, GitHub OAuth, magic link, email+password all configured in the Supabase dashboard (no code for provider setup)
|
||||
- Prisma connects to Supabase Postgres via standard `DATABASE_URL` — app data (plugins, installs, etc.) lives alongside auth tables
|
||||
- Well-trodden Stripe + Supabase integration path via the [Vercel subscription payments starter](https://github.com/vercel/nextjs-subscription-payments)
|
||||
- Free tier covers early-stage Marketplace comfortably
|
||||
- `@supabase/ssr` package has first-class Next.js App Router support (server components, middleware, server actions)
|
||||
|
||||
**Accepted tradeoff:** Supabase vendor dependency — if pricing changes at scale, migration to self-hosted Postgres + Better Auth is straightforward because Prisma abstracts the DB layer.
|
||||
|
||||
**Known gotcha — cookie domain across subdomains:** Supabase session cookies are scoped per-app by default. A session from `marketplace.worldwideview.dev` does not automatically carry over to `app.worldwideview.dev`. Fix: after login on either app, set a shared JWT cookie on the parent domain `worldwideview.dev` (via custom middleware) that both subdomains can read and validate against the shared Supabase public key. This is the only custom plumbing required — both apps still use the same Supabase JWT secret for validation.
|
||||
|
||||
**Upgrade path:** If the Marketplace later needs to support third-party app integrations (external developers building plugins), flip to the **Marketplace-as-OAuth-Provider** model — the user table stays the same, you add the PKCE authorization layer on top. No user migration needed.
|
||||
|
||||
---
|
||||
|
||||
## What to Build
|
||||
|
||||
### Step 1 — Create Supabase Project
|
||||
|
||||
1. Go to supabase.com → New project → name it `wwv-marketplace`
|
||||
2. In **Authentication → Providers**, enable:
|
||||
- **Email** (email+password + magic link)
|
||||
- **Google** (add Client ID + Secret from Google Cloud Console)
|
||||
- **GitHub** (add Client ID + Secret from GitHub OAuth App)
|
||||
3. Save the project URL and anon key (go into `.env.local`)
|
||||
|
||||
### Step 2 — Install Packages
|
||||
|
||||
```bash
|
||||
pnpm add @supabase/supabase-js @supabase/ssr
|
||||
pnpm add -D prisma @prisma/client
|
||||
```
|
||||
|
||||
### Step 3 — Configure Environment Variables
|
||||
|
||||
```env
|
||||
# Supabase
|
||||
NEXT_PUBLIC_SUPABASE_URL=https://xxxx.supabase.co
|
||||
NEXT_PUBLIC_SUPABASE_ANON_KEY=eyJ...
|
||||
SUPABASE_SERVICE_ROLE_KEY=eyJ... # server-only, never expose to client
|
||||
|
||||
# Prisma (Supabase Postgres — use the "Transaction" pooler URL)
|
||||
DATABASE_URL=postgresql://postgres.[ref]:[password]@aws-0-[region].pooler.supabase.com:6543/postgres?pgbouncer=true
|
||||
DIRECT_URL=postgresql://postgres.[ref]:[password]@aws-0-[region].pooler.supabase.com:5432/postgres
|
||||
|
||||
# Ed25519 key for plugin ticket signing (ADR-001B)
|
||||
MARKETPLACE_ED25519_PRIVATE_KEY= # base64 PEM
|
||||
MARKETPLACE_ED25519_KID= # key ID (for JWKS rotation)
|
||||
|
||||
# OAuth server (PKCE for Local App)
|
||||
OAUTH_CLIENT_REDIRECT_URI_ALLOWLIST=http://localhost:3000/api/marketplace/callback,https://app.worldwideview.dev/api/marketplace/callback
|
||||
```
|
||||
|
||||
### Step 4 — Supabase Client Helpers
|
||||
|
||||
**`src/lib/supabase/server.ts`** — server-side client (server components, server actions, API routes):
|
||||
```ts
|
||||
import { createServerClient } from "@supabase/ssr"
|
||||
import { cookies } from "next/headers"
|
||||
|
||||
export function createClient() {
|
||||
const cookieStore = cookies()
|
||||
return createServerClient(
|
||||
process.env.NEXT_PUBLIC_SUPABASE_URL!,
|
||||
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
|
||||
{ cookies: { getAll: () => cookieStore.getAll(), setAll: (c) => c.forEach(({ name, value, options }) => cookieStore.set(name, value, options)) } }
|
||||
)
|
||||
}
|
||||
```
|
||||
|
||||
**`src/lib/supabase/client.ts`** — browser client:
|
||||
```ts
|
||||
import { createBrowserClient } from "@supabase/ssr"
|
||||
export const supabase = createBrowserClient(
|
||||
process.env.NEXT_PUBLIC_SUPABASE_URL!,
|
||||
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!
|
||||
)
|
||||
```
|
||||
|
||||
### Step 5 — Auth Middleware (session refresh)
|
||||
|
||||
**`src/middleware.ts`** — refreshes Supabase session on every request:
|
||||
```ts
|
||||
import { createServerClient } from "@supabase/ssr"
|
||||
import { NextResponse, type NextRequest } from "next/server"
|
||||
|
||||
export async function middleware(request: NextRequest) {
|
||||
let response = NextResponse.next({ request })
|
||||
const supabase = createServerClient(
|
||||
process.env.NEXT_PUBLIC_SUPABASE_URL!,
|
||||
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
|
||||
{ cookies: { getAll: () => request.cookies.getAll(), setAll: (c) => c.forEach(({ name, value, options }) => response.cookies.set(name, value, options)) } }
|
||||
)
|
||||
await supabase.auth.getUser() // refreshes session token
|
||||
return response
|
||||
}
|
||||
export const config = { matcher: ["/((?!_next/static|_next/image|favicon.ico).*)"] }
|
||||
```
|
||||
|
||||
### Step 6 — Auth Callback Route
|
||||
|
||||
**`src/app/auth/callback/route.ts`** — Supabase redirects here after social login to exchange the code for a session:
|
||||
```ts
|
||||
import { createClient } from "@/lib/supabase/server"
|
||||
import { NextResponse } from "next/server"
|
||||
|
||||
export async function GET(request: Request) {
|
||||
const { searchParams, origin } = new URL(request.url)
|
||||
const code = searchParams.get("code")
|
||||
const next = searchParams.get("next") ?? "/"
|
||||
if (code) {
|
||||
const supabase = createClient()
|
||||
await supabase.auth.exchangeCodeForSession(code)
|
||||
}
|
||||
return NextResponse.redirect(`${origin}${next}`)
|
||||
}
|
||||
```
|
||||
|
||||
### Step 7 — Login UI
|
||||
|
||||
**`src/app/login/page.tsx`** — single page with four auth methods:
|
||||
- Email + password (`supabase.auth.signInWithPassword()`)
|
||||
- Google (`supabase.auth.signInWithOAuth({ provider: "google" })`)
|
||||
- GitHub (`supabase.auth.signInWithOAuth({ provider: "github" })`)
|
||||
- Magic link (`supabase.auth.signInWithOtp({ email })`)
|
||||
|
||||
All OAuth redirects must include `redirectTo: "${origin}/auth/callback"`.
|
||||
|
||||
### Step 8 — Prisma Schema for App Data
|
||||
|
||||
Supabase manages the `auth.users` table internally. For app-specific data, add to `prisma/schema.prisma`:
|
||||
|
||||
```prisma
|
||||
// References Supabase auth.users UUID — do NOT store password/session data here
|
||||
model MarketplaceUser {
|
||||
id String @id // matches auth.users.id (UUID)
|
||||
email String @unique
|
||||
plan String @default("free") // "free" | "pro" | "team"
|
||||
stripeCustomerId String?
|
||||
createdAt DateTime @default(now())
|
||||
plugins InstalledPlugin[]
|
||||
}
|
||||
|
||||
model InstalledPlugin {
|
||||
id String @id @default(cuid())
|
||||
userId String
|
||||
pluginId String
|
||||
installedAt DateTime @default(now())
|
||||
user MarketplaceUser @relation(fields: [userId], references: [id])
|
||||
@@unique([userId, pluginId])
|
||||
}
|
||||
```
|
||||
|
||||
Run `prisma migrate dev` pointing at the Supabase Postgres URL.
|
||||
|
||||
### Step 9 — OAuth 2.0 PKCE Authorization Server (for Local App)
|
||||
|
||||
This is the custom layer that lets the Local App "connect" to the Marketplace. Supabase handles user identity; these routes handle the code exchange.
|
||||
|
||||
**`src/app/api/oauth/authorize/route.ts`**
|
||||
- Validates: `client_id`, `redirect_uri` (must match allowlist), `code_challenge`, `code_challenge_method=S256`, `state`
|
||||
- Calls `supabase.auth.getUser()` — if not logged in, redirects to `/login?redirect_to=...`
|
||||
- Shows a consent screen ("Allow WorldWideView Local App to access your account?")
|
||||
- On approval: stores `{ code, code_challenge, user_id, expires: now+60s }` in Supabase DB, redirects to `redirect_uri?code=...&state=...`
|
||||
|
||||
**`src/app/api/oauth/token/route.ts`**
|
||||
- Validates `code` + `code_verifier` (SHA-256(`code_verifier`) must equal stored `code_challenge`)
|
||||
- Issues a long-lived API Key (random 32-byte token), stores hashed in DB
|
||||
- Returns `{ access_token, token_type: "Bearer" }` — this is what the Local App encrypts and stores
|
||||
|
||||
**`src/app/api/auth/exchange/route.ts`** *(ADR-001B)*
|
||||
- Accepts API Key + `audience` (plugin ID)
|
||||
- Verifies API Key against DB, checks subscription tier
|
||||
- Issues a 5-minute EdDSA JWT signed with the Marketplace Ed25519 key, scoped to the requested plugin
|
||||
- Data Engines verify this JWT via the public JWKS endpoint
|
||||
|
||||
**`src/app/.well-known/jwks.json/route.ts`**
|
||||
- Returns the Marketplace's Ed25519 public key in JWKS format
|
||||
- Data Engines call this on startup and cache it (ADR-001A)
|
||||
|
||||
---
|
||||
|
||||
## Critical Files (Marketplace repo: `c:/dev/worldwideview-marketplace`)
|
||||
|
||||
| File | Purpose |
|
||||
|---|---|
|
||||
| `src/lib/supabase/server.ts` | Server-side Supabase client |
|
||||
| `src/lib/supabase/client.ts` | Browser-side Supabase client |
|
||||
| `src/middleware.ts` | Session refresh on every request |
|
||||
| `src/app/auth/callback/route.ts` | OAuth callback from Supabase (social login) |
|
||||
| `src/app/login/page.tsx` | Login UI (all 4 methods) |
|
||||
| `prisma/schema.prisma` | App data schema (MarketplaceUser, InstalledPlugin) |
|
||||
| `src/app/api/oauth/authorize/route.ts` | PKCE auth endpoint (Local App connects here) |
|
||||
| `src/app/api/oauth/token/route.ts` | PKCE token exchange |
|
||||
| `src/app/api/auth/exchange/route.ts` | API Key → 5-min EdDSA JWT (ADR-001B) |
|
||||
| `src/app/.well-known/jwks.json/route.ts` | Public JWKS for Data Engine JWT verification |
|
||||
| `.env.local` | Supabase + Prisma + Ed25519 keys |
|
||||
|
||||
---
|
||||
|
||||
## Stripe Integration Path (Future)
|
||||
|
||||
When ready to add payments:
|
||||
1. Install `stripe` + `@stripe/stripe-js`
|
||||
2. On user signup (Supabase `auth.onAuthStateChange`), create a Stripe customer and save `stripeCustomerId` to `MarketplaceUser`
|
||||
3. Use Stripe Billing for subscriptions — webhook updates `MarketplaceUser.plan`
|
||||
4. The `exchange` endpoint reads `plan` to enforce tier in the issued JWT (`tier` claim per ADR-001B)
|
||||
|
||||
Reference: [Vercel Next.js + Supabase + Stripe starter](https://github.com/vercel/nextjs-subscription-payments)
|
||||
|
||||
---
|
||||
|
||||
---
|
||||
|
||||
## Risk Mitigations (Pre-Mortem — 2026-05-22)
|
||||
|
||||
### Tigers Addressed
|
||||
|
||||
**[HIGH] RLS not configured on app tables**
|
||||
- All tables that contain user-scoped data (`MarketplaceUser`, `InstalledPlugin`) MUST have Row Level Security enabled in Supabase before going live.
|
||||
- Add to `prisma/migrations/` as a raw SQL migration (Prisma doesn't support RLS natively):
|
||||
```sql
|
||||
ALTER TABLE "MarketplaceUser" ENABLE ROW LEVEL SECURITY;
|
||||
CREATE POLICY "Users can only access own row" ON "MarketplaceUser"
|
||||
USING (id = auth.uid());
|
||||
|
||||
ALTER TABLE "InstalledPlugin" ENABLE ROW LEVEL SECURITY;
|
||||
CREATE POLICY "Users can only access own plugins" ON "InstalledPlugin"
|
||||
USING ("userId" = auth.uid());
|
||||
```
|
||||
- Server-side routes that need full access use `SUPABASE_SERVICE_ROLE_KEY` (bypasses RLS by design — keep it server-only, never expose to client).
|
||||
|
||||
**[HIGH] Authorization code not invalidated after use**
|
||||
- In `/api/oauth/token/route.ts`, wrap the validation and API Key issuance in a transaction:
|
||||
1. `SELECT` the code row (validate `code_challenge`)
|
||||
2. `DELETE` the code row
|
||||
3. Issue the API Key
|
||||
4. Commit
|
||||
- If the DELETE fails or the row is already gone, return `400 invalid_grant`. This prevents replay attacks within the 60s window.
|
||||
|
||||
### Medium Risks Addressed
|
||||
|
||||
**[MEDIUM] Supabase email rate limit breaks magic link**
|
||||
- Configure a custom SMTP provider in Supabase Dashboard → Project Settings → Auth → SMTP Settings before enabling magic link in production.
|
||||
- Recommended: Resend (free tier = 3,000 emails/month, 100/day). Add `RESEND_API_KEY` to env and configure in Supabase dashboard — no code change needed.
|
||||
|
||||
**[MEDIUM] MarketplaceUser orphan on auth.users delete**
|
||||
- Add a Postgres trigger via raw SQL migration:
|
||||
```sql
|
||||
CREATE OR REPLACE FUNCTION handle_deleted_user()
|
||||
RETURNS TRIGGER LANGUAGE plpgsql SECURITY DEFINER AS $$
|
||||
BEGIN
|
||||
DELETE FROM "MarketplaceUser" WHERE id = OLD.id;
|
||||
RETURN OLD;
|
||||
END;
|
||||
$$;
|
||||
|
||||
CREATE TRIGGER on_auth_user_deleted
|
||||
AFTER DELETE ON auth.users
|
||||
FOR EACH ROW EXECUTE PROCEDURE handle_deleted_user();
|
||||
```
|
||||
|
||||
**[MEDIUM] Ed25519 key rotation — no zero-downtime strategy**
|
||||
- Do not store the Ed25519 key only in an env var. Add a `SigningKey` table to Prisma schema:
|
||||
```prisma
|
||||
model SigningKey {
|
||||
kid String @id
|
||||
publicKey String // PEM, served in JWKS
|
||||
privateKey String // encrypted at rest
|
||||
status String // "active" | "retiring" | "revoked"
|
||||
expiresAt DateTime?
|
||||
createdAt DateTime @default(now())
|
||||
}
|
||||
```
|
||||
- The JWKS endpoint serves ALL `status != "revoked"` keys. During rotation: add a new key (`active`), flip the old key to `retiring`, wait 10 minutes for Data Engine caches to expire, then flip old key to `revoked`.
|
||||
|
||||
### Accepted Risks
|
||||
- None — all identified risks have been mitigated in plan.
|
||||
|
||||
---
|
||||
|
||||
## Verification
|
||||
|
||||
1. **Social login:** Click "Continue with Google" → Google OAuth flow → redirects to `/auth/callback` → lands on dashboard logged in
|
||||
2. **Magic link:** Enter email → receive email → click link → logged in
|
||||
3. **PKCE flow (end-to-end):** From Local App, click "Connect to Marketplace" → redirected to `/api/oauth/authorize` → must log in first if not logged in → consent screen → approve → back to Local App with `code` → Local App calls `/api/oauth/token` → receives API Key → stored encrypted in Local App DB
|
||||
4. **Plugin ticket:** Local App POSTs API Key + `audience` to `/api/auth/exchange` → receives 5-min JWT → browser sends as WebSocket first message to Data Engine → engine verifies via JWKS → stream opens
|
||||
5. **Unauthenticated protection:** Hit `/api/oauth/authorize` without a session → must redirect to login, not error
|
||||
@@ -0,0 +1,578 @@
|
||||
# Phase 4 Coolify Cutover 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:** Flip the production WorldWideView data engine from "auth disabled" (`WWV_SKIP_WS_AUTH=true`) to "auth enforced" (`JWKS_URL` set + ticket-auth plugin allowlist enumerated) in a single atomic redeploy window, with smoke tests proving every plugin still works.
|
||||
|
||||
**Architecture:** Pure ops change — no source code modifications. Two Coolify services receive env-var updates (`wwv-data-engine` and `wwv` frontend), both are redeployed near-simultaneously, smoke-tested through the live UI. Rollback is a single env-var revert + redeploy.
|
||||
|
||||
**Tech Stack:** Coolify CLI (context `wwv` pre-configured), `curl` for registry/JWKS probing, optional SSH to the host for low-level diagnostics. No code, no tests, no commits — only env config + deploy actions.
|
||||
|
||||
---
|
||||
|
||||
## Context — why this plan exists
|
||||
|
||||
Phase 4 of the Northstar Sequence shipped the data engine's WebSocket JWT enforcement code (engine-side: PR #10 merged on `wwv-data-engine`; frontend ticket-issuance and PKCE flow merged earlier in worldwideview/marketplace). The enforcement is currently **dormant** in production because the Coolify env still has `WWV_SKIP_WS_AUTH=true`, which the engine reads at boot to bypass first-message auth.
|
||||
|
||||
Local end-to-end testing in the prior session proved the full chain works:
|
||||
- PKCE → marketplace API key (encrypted in `MarketplaceCredential`)
|
||||
- `/api/auth/ticket` → 5-min EdDSA JWT signed by marketplace
|
||||
- WebSocket first frame: `{type:"auth", v:1, token}` → engine validates against marketplace JWKS → `welcome` → subscribe → data flows
|
||||
|
||||
The pre-mortem identified four tigers blocking the cutover. The companion plan (`joyful-napping-gizmo.md`) addresses three via CI hardening and the `BaseIncidentPlugin` payload fix. **This plan handles the remaining tiger (T3 — production JWKS reachability never verified) and the elephants (E1 — plugin enumeration never done, E2 — current Coolify state unknown), then performs the actual flip.**
|
||||
|
||||
**Prerequisites — the companion plan must be fully landed:**
|
||||
- PR1 `feat/ci-coverage-phase4` merged on `wwv-data-engine` main (CI guards live)
|
||||
- PR2 `test/base-incident-plugin-payload` merged on `worldwideview` main (test guards live)
|
||||
- PR3 `fix/base-incident-plugin-payload` merged on `worldwideview` main (earthquakes data fix live)
|
||||
- Worldwideview Coolify service has redeployed since PR3 landed (so the new frontend bundle contains the `mapWebsocketPayload` fix)
|
||||
|
||||
Without PR3 deployed, enabling Earthquakes in the cutover allowlist will show an empty layer — the test we ran locally would re-occur in production.
|
||||
|
||||
---
|
||||
|
||||
## File Structure
|
||||
|
||||
This plan modifies **zero source files**. All changes are Coolify env-var updates plus the documents created during audit:
|
||||
|
||||
| Path | Role | Lifecycle |
|
||||
|---|---|---|
|
||||
| `C:\Users\silve\.claude\plans\coolify-baseline-<timestamp>.md` | Captured baseline of current Coolify env state (rollback reference) | created in Task 3 |
|
||||
| `C:\Users\silve\.claude\plans\coolify-cutover-allowlist-<timestamp>.md` | Computed plugin allowlist (CSV + rationale) | created in Task 4 |
|
||||
| `worldwideview/docs/architecture/decisions/adr-0001b-status.md` *(optional)* | ADR-001B status update — Proposed → Accepted | Task 13 (post-success only) |
|
||||
|
||||
The Coolify services touched:
|
||||
- **`wwv-data-engine`** — set `JWKS_URL`, remove `WWV_SKIP_WS_AUTH`
|
||||
- **`wwv`** (the worldwideview frontend) — set `NEXT_PUBLIC_WWV_TICKET_AUTH_PLUGINS`
|
||||
|
||||
---
|
||||
|
||||
## Task 1: Confirm prerequisites are live in production
|
||||
|
||||
**Files:** none. Read-only verification.
|
||||
|
||||
- [ ] **Step 1: Verify all three companion-plan PRs are merged**
|
||||
|
||||
```powershell
|
||||
gh pr list --repo silvertakana/wwv-data-engine --state merged --limit 5
|
||||
gh pr list --repo silvertakana/worldwideview --state merged --limit 5
|
||||
```
|
||||
|
||||
Expected: see merged PRs titled `test(auth): Phase 4 WebSocket auth + port-contract CI guards` (wwv-data-engine), `test(incidents): guard BaseIncidentPlugin WebSocket payload contract` and `fix(incidents): add mapWebsocketPayload default to BaseIncidentPlugin` (worldwideview). If any is missing, STOP — return to the companion plan.
|
||||
|
||||
- [ ] **Step 2: Verify the worldwideview Coolify deploy includes PR3**
|
||||
|
||||
```powershell
|
||||
coolify deploy status wwv
|
||||
```
|
||||
|
||||
Expected: `last deploy` timestamp is AFTER PR3 merge. If older, trigger a redeploy first:
|
||||
|
||||
```powershell
|
||||
coolify deploy trigger wwv
|
||||
```
|
||||
|
||||
Wait for completion (`coolify deploy status wwv --watch`). The cutover later will trigger this again, but verifying the fix is deployed BEFORE the cutover ensures we can isolate any failure to env vs. code.
|
||||
|
||||
- [ ] **Step 3: Confirm the data engine code already has Phase 4 (PR #10)**
|
||||
|
||||
```powershell
|
||||
curl https://dataenginev2.worldwideview.dev/health
|
||||
```
|
||||
|
||||
Expected: JSON with `version: "1.7.3"` (or newer if CI tests bumped further). If `1.7.1` or earlier, PR #10 is not deployed — STOP.
|
||||
|
||||
---
|
||||
|
||||
## Task 2: Verify the marketplace JWKS endpoint is reachable from the public internet
|
||||
|
||||
**Files:** none.
|
||||
|
||||
- [ ] **Step 1: Curl from the local workstation**
|
||||
|
||||
```powershell
|
||||
curl -v https://marketplace.worldwideview.dev/api/auth/jwks
|
||||
```
|
||||
|
||||
Expected: HTTP 200, body is JSON like `{"keys":[{"kty":"OKP","crv":"Ed25519","x":"...","kid":"marketplace-key-v1","alg":"EdDSA"}]}`. If 404/500/timeout → STOP, fix the marketplace before continuing.
|
||||
|
||||
- [ ] **Step 2: Validate the JWK shape**
|
||||
|
||||
The response must include at least one key with `kty: "OKP"`, `crv: "Ed25519"`, `alg: "EdDSA"`, and a non-empty `kid`. If any of those are missing, the engine's `verifyEngineToken` will reject every token with "no applicable key found" — same symptom as our local test isolation bug. STOP if shape is wrong.
|
||||
|
||||
---
|
||||
|
||||
## Task 3: Capture Coolify baseline (rollback reference)
|
||||
|
||||
**Files:**
|
||||
- Create: `C:\Users\silve\.claude\plans\coolify-baseline-<YYYYMMDD-HHMMSS>.md`
|
||||
|
||||
- [ ] **Step 1: Dump current data engine env vars**
|
||||
|
||||
```powershell
|
||||
coolify env list wwv-data-engine
|
||||
```
|
||||
|
||||
- [ ] **Step 2: Dump current frontend env vars**
|
||||
|
||||
```powershell
|
||||
coolify env list wwv
|
||||
```
|
||||
|
||||
- [ ] **Step 3: Save baseline to file**
|
||||
|
||||
Create `C:\Users\silve\.claude\plans\coolify-baseline-<YYYYMMDD-HHMMSS>.md` with the exact current values of these keys (copy from the `coolify env list` output):
|
||||
|
||||
```markdown
|
||||
# Coolify baseline — captured <ISO timestamp>
|
||||
|
||||
## wwv-data-engine
|
||||
- JWKS_URL: <current value or "(unset)">
|
||||
- WWV_SKIP_WS_AUTH: <current value or "(unset)">
|
||||
- ENGINE_ID: <current value or "(unset)">
|
||||
- REDIS_URL: <redacted — confirm present>
|
||||
- SENTRY_DSN: <redacted — confirm present>
|
||||
|
||||
## wwv (frontend)
|
||||
- NEXT_PUBLIC_WWV_TICKET_AUTH_PLUGINS: <current value or "(unset)">
|
||||
- NEXT_PUBLIC_WWV_PLUGIN_DATA_ENGINE_URL: <current value>
|
||||
- NEXT_PUBLIC_WWV_MARKETPLACE_URL: <current value>
|
||||
- NEXT_PUBLIC_WWV_EDITION: <current value>
|
||||
|
||||
## Rollback procedure
|
||||
If anything breaks during/after cutover:
|
||||
1. coolify env set wwv-data-engine WWV_SKIP_WS_AUTH=true
|
||||
2. coolify env unset wwv-data-engine JWKS_URL (or set to "(unset)" value above)
|
||||
3. coolify env unset wwv NEXT_PUBLIC_WWV_TICKET_AUTH_PLUGINS (or restore "(unset)" value above)
|
||||
4. coolify deploy trigger wwv-data-engine
|
||||
5. coolify deploy trigger wwv
|
||||
6. curl https://dataenginev2.worldwideview.dev/health — confirm version unchanged, engine running
|
||||
```
|
||||
|
||||
This file is the **single source of truth** for rollback. Do not skip it.
|
||||
|
||||
---
|
||||
|
||||
## Task 4: Compute the plugin allowlist from the live data engine manifest
|
||||
|
||||
**Files:**
|
||||
- Create: `C:\Users\silve\.claude\plans\coolify-cutover-allowlist-<YYYYMMDD-HHMMSS>.md`
|
||||
|
||||
- [ ] **Step 1: Fetch the live manifest from production**
|
||||
|
||||
```powershell
|
||||
curl https://dataenginev2.worldwideview.dev/manifest
|
||||
```
|
||||
|
||||
Expected: JSON like `{"engine":"wwv-data-engine","version":"1.7.3","plugins":["earthquakes","wildfires","sanctions","conflict-events","gps-jamming","cyber-attacks","civil-unrest","iss","satellites","aviation-history","maritime-history","iranwar-events"],"websocket":"/stream","timestamp":...}`. The exact list will vary — capture whatever is returned.
|
||||
|
||||
- [ ] **Step 2: Build the CSV**
|
||||
|
||||
Take the `plugins` array from the response and join with commas (no spaces). Example:
|
||||
|
||||
```
|
||||
earthquakes,wildfires,sanctions,conflict-events,gps-jamming,cyber-attacks,civil-unrest,iss,satellites,aviation-history,maritime-history,iranwar-events
|
||||
```
|
||||
|
||||
- [ ] **Step 3: Cross-check against the marketplace verified registry (sanity)**
|
||||
|
||||
```powershell
|
||||
curl https://marketplace.worldwideview.dev/api/registry
|
||||
```
|
||||
|
||||
Compare the engine manifest's plugin IDs against the registry's verified IDs. Note any discrepancies:
|
||||
- Manifest plugins NOT in registry → in-house seeders not advertised on marketplace (fine, still need auth)
|
||||
- Registry plugins NOT in manifest → marketplace-only or static plugins (fine, don't need auth)
|
||||
|
||||
The **engine manifest is authoritative** for the allowlist — anything that streams from this engine needs to be there.
|
||||
|
||||
- [ ] **Step 4: Save the computed allowlist**
|
||||
|
||||
Create `C:\Users\silve\.claude\plans\coolify-cutover-allowlist-<YYYYMMDD-HHMMSS>.md`:
|
||||
|
||||
```markdown
|
||||
# Phase 4 Coolify cutover — plugin allowlist
|
||||
|
||||
Captured from: https://dataenginev2.worldwideview.dev/manifest at <ISO timestamp>
|
||||
|
||||
## Allowlist (CSV form for NEXT_PUBLIC_WWV_TICKET_AUTH_PLUGINS)
|
||||
|
||||
<the CSV from Step 2>
|
||||
|
||||
## Per-plugin rationale
|
||||
|
||||
| Plugin | In manifest | In registry | Action |
|
||||
|---|---|---|---|
|
||||
| earthquakes | yes | yes | include |
|
||||
| wildfires | yes | yes | include |
|
||||
| <one row per plugin> | | | |
|
||||
|
||||
## Notes
|
||||
- Engine manifest is authoritative.
|
||||
- Registry sanity-checked at Step 3 — discrepancies noted above.
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Task 5: Smoke-test JWKS reachability FROM the production data engine container
|
||||
|
||||
**Files:** none.
|
||||
|
||||
The engine's startup check (`startup-checks.ts`) verifies JWKS is reachable at boot — but a one-shot check at boot doesn't catch transient network policy issues that appear later. Pre-flight this from inside the actual container to catch firewall/DNS surprises.
|
||||
|
||||
- [ ] **Step 1: Exec into the container via Coolify**
|
||||
|
||||
```powershell
|
||||
coolify exec wwv-data-engine -- curl -v https://marketplace.worldwideview.dev/api/auth/jwks
|
||||
```
|
||||
|
||||
If `coolify exec` is not available, fall back to SSH:
|
||||
|
||||
```bash
|
||||
ssh root@<coolify-host>
|
||||
docker exec -it $(docker ps --filter "name=wwv-data-engine" -q) curl -v https://marketplace.worldwideview.dev/api/auth/jwks
|
||||
```
|
||||
|
||||
The Coolify host IP is in your server-dev memory; if unsure, run `coolify host info`.
|
||||
|
||||
- [ ] **Step 2: Verify the response**
|
||||
|
||||
Expected: HTTP 200, same JWKS body as Task 2 Step 1. If the local workstation can reach JWKS but the container cannot, you have a Coolify network policy issue (egress firewall, DNS) — STOP and fix the network before continuing.
|
||||
|
||||
---
|
||||
|
||||
## Task 6: Set the new env vars on Coolify (no redeploy yet)
|
||||
|
||||
**Files:** none. Coolify state-only.
|
||||
|
||||
Setting env vars in Coolify does NOT trigger a deploy by default — the new values take effect at the next start. We set BOTH services' new env vars first, then trigger redeploys near-simultaneously so the atomic-flip window is small.
|
||||
|
||||
- [ ] **Step 1: Set `JWKS_URL` on the data engine**
|
||||
|
||||
```powershell
|
||||
coolify env set wwv-data-engine JWKS_URL=https://marketplace.worldwideview.dev/api/auth/jwks
|
||||
```
|
||||
|
||||
Expected: confirmation message. Verify with `coolify env get wwv-data-engine JWKS_URL`.
|
||||
|
||||
- [ ] **Step 2: Remove (or set false) `WWV_SKIP_WS_AUTH` on the data engine**
|
||||
|
||||
```powershell
|
||||
coolify env unset wwv-data-engine WWV_SKIP_WS_AUTH
|
||||
```
|
||||
|
||||
(If `unset` is not supported, use `coolify env set wwv-data-engine WWV_SKIP_WS_AUTH=false` — the engine reads `=== 'true'` so anything else is treated as enforcement-on.)
|
||||
|
||||
Verify with `coolify env get wwv-data-engine WWV_SKIP_WS_AUTH` — should return empty/false.
|
||||
|
||||
- [ ] **Step 3: Set `NEXT_PUBLIC_WWV_TICKET_AUTH_PLUGINS` on the frontend**
|
||||
|
||||
Use the CSV from Task 4 Step 2. Example:
|
||||
|
||||
```powershell
|
||||
coolify env set wwv NEXT_PUBLIC_WWV_TICKET_AUTH_PLUGINS=earthquakes,wildfires,sanctions,conflict-events,gps-jamming,cyber-attacks,civil-unrest,iss,satellites,aviation-history,maritime-history,iranwar-events
|
||||
```
|
||||
|
||||
Verify with `coolify env get wwv NEXT_PUBLIC_WWV_TICKET_AUTH_PLUGINS` — should return the CSV verbatim.
|
||||
|
||||
- [ ] **Step 4: Cross-check the saved values against the baseline file**
|
||||
|
||||
Open `C:\Users\silve\.claude\plans\coolify-baseline-<...>.md` and confirm the three values you just changed are different from baseline. This is the "I really did change them" sanity check.
|
||||
|
||||
---
|
||||
|
||||
## Task 7: Trigger redeploys for both services
|
||||
|
||||
**Files:** none.
|
||||
|
||||
Both redeploys should be triggered as close together as possible (within ~1 minute) so the user-facing flip is single-window. Coolify deploys are non-blocking; we trigger both then watch both.
|
||||
|
||||
- [ ] **Step 1: Trigger data engine deploy**
|
||||
|
||||
```powershell
|
||||
coolify deploy trigger wwv-data-engine
|
||||
```
|
||||
|
||||
Capture the deploy ID printed.
|
||||
|
||||
- [ ] **Step 2: Trigger frontend deploy**
|
||||
|
||||
```powershell
|
||||
coolify deploy trigger wwv
|
||||
```
|
||||
|
||||
Capture the deploy ID printed.
|
||||
|
||||
- [ ] **Step 3: Watch both deploys complete**
|
||||
|
||||
In one terminal:
|
||||
```powershell
|
||||
coolify deploy status wwv-data-engine --watch
|
||||
```
|
||||
|
||||
In another (parallel):
|
||||
```powershell
|
||||
coolify deploy status wwv --watch
|
||||
```
|
||||
|
||||
Expected: both reach `running` state within ~3-5 minutes. The data engine log will show `[Server] JWKS reachable at https://marketplace.worldwideview.dev/api/auth/jwks` — that is the moment enforcement goes live.
|
||||
|
||||
- [ ] **Step 4: STOP and rollback if either deploy fails**
|
||||
|
||||
If `wwv-data-engine` startup fails with `FATAL: JWKS unreachable at startup`, the network/JWKS smoke (Task 5) gave a false positive. Rollback immediately (Task 12) and investigate before retrying.
|
||||
|
||||
If `wwv` build fails, the env var format may be wrong (Coolify can sometimes mangle commas) — check the build log and re-set the env var with proper escaping.
|
||||
|
||||
---
|
||||
|
||||
## Task 8: Post-deploy smoke — engine endpoints
|
||||
|
||||
**Files:** none.
|
||||
|
||||
- [ ] **Step 1: Health check**
|
||||
|
||||
```powershell
|
||||
curl https://dataenginev2.worldwideview.dev/health
|
||||
```
|
||||
|
||||
Expected: `{"status":"ok","engine":"wwv-data-engine","timestamp":<recent>,"seeders":{...}}`. The `seeders` object should list every plugin in the manifest with a recent `lastSuccess` timestamp.
|
||||
|
||||
- [ ] **Step 2: Manifest check**
|
||||
|
||||
```powershell
|
||||
curl https://dataenginev2.worldwideview.dev/manifest
|
||||
```
|
||||
|
||||
Expected: same plugin list as Task 4 Step 1 (no regression). If a plugin dropped out, a seeder failed to load — investigate before continuing.
|
||||
|
||||
---
|
||||
|
||||
## Task 9: Post-deploy smoke — WebSocket auth handshake (curl-based)
|
||||
|
||||
**Files:** none.
|
||||
|
||||
Confirms enforcement is actually ON before testing the UI.
|
||||
|
||||
- [ ] **Step 1: Attempt unauthenticated WebSocket connection**
|
||||
|
||||
```powershell
|
||||
# Use websocat or wscat — install via: pnpm dlx wscat
|
||||
pnpm dlx wscat -c wss://dataenginev2.worldwideview.dev/stream
|
||||
```
|
||||
|
||||
Then send (paste into the open prompt):
|
||||
```
|
||||
{"action":"subscribe","pluginId":"earthquakes"}
|
||||
```
|
||||
|
||||
Expected: connection closes immediately with code `4003`. If the connection stays open and you receive data, **enforcement is NOT active** — the env var didn't apply, restart the data engine via `coolify deploy trigger wwv-data-engine` and retry.
|
||||
|
||||
---
|
||||
|
||||
## Task 10: Post-deploy smoke — UI walkthrough (the real test)
|
||||
|
||||
**Files:** none.
|
||||
|
||||
- [ ] **Step 1: Open the production app in a browser**
|
||||
|
||||
Navigate to `https://worldwideview.dev` (or whatever the production frontend URL is). Sign in if not already.
|
||||
|
||||
- [ ] **Step 2: Open browser DevTools — Network tab, filter "WS"**
|
||||
|
||||
You'll see WebSocket connections appear as you enable plugins.
|
||||
|
||||
- [ ] **Step 3: Enable EACH plugin in the allowlist, one at a time**
|
||||
|
||||
For each plugin in the CSV from Task 4:
|
||||
1. Enable it via the UI control (sidebar, search, etc.)
|
||||
2. Observe the new `wss://dataenginev2.worldwideview.dev/stream` WebSocket in the Network tab
|
||||
3. Click it → Messages tab → confirm:
|
||||
- First **outbound** message: `{"type":"auth","v":1,"token":"<long EdDSA JWT>"}`
|
||||
- First **inbound** message: `{"type":"welcome","engine":"wwv-data-engine","plugins":[...]}`
|
||||
- Subsequent inbound: `{"type":"data","pluginId":"<this plugin>","payload":...}`
|
||||
4. Confirm visible markers/data appear on the globe
|
||||
5. **If any plugin closes with `4003`** in the Network tab → that plugin is broken under enforcement. Capture the plugin ID, then either:
|
||||
- Continue smoke-testing remaining plugins (note all failures)
|
||||
- OR rollback immediately if it's a high-traffic plugin (your call)
|
||||
|
||||
- [ ] **Step 4: Specific check — Earthquakes**
|
||||
|
||||
This is the plugin we expected to break before PR3 landed. Confirm:
|
||||
- WebSocket connects with auth handshake
|
||||
- `data` messages arrive
|
||||
- Earthquake markers appear on the globe (NOT an empty layer)
|
||||
|
||||
If markers don't appear but the auth handshake succeeded and `data` messages are arriving, PR3 didn't deploy — re-trigger the worldwideview deploy.
|
||||
|
||||
- [ ] **Step 5: Negative smoke — sign out, retry**
|
||||
|
||||
Sign out of the app. Try to enable a cloud plugin. Expected: WebSocket either doesn't connect or closes with `4003`/`4001` quickly. The frontend's `/api/auth/ticket` route should return 401 because no NextAuth session exists. If unauthenticated users CAN still get data, the ticket route's session check is broken — file an issue.
|
||||
|
||||
---
|
||||
|
||||
## Task 11: Decision point — happy path OR rollback
|
||||
|
||||
**Files:** none.
|
||||
|
||||
- [ ] **Step 1: Evaluate smoke results**
|
||||
|
||||
| Outcome | Action |
|
||||
|---|---|
|
||||
| All plugins green, all WebSockets auth-handshake-then-data | Skip to Task 13 (mark Phase 4 done) |
|
||||
| 1-2 minor plugins break (low-traffic, niche) | Document failures, keep enforcement on, file fix issues — Task 13 with caveats |
|
||||
| Earthquakes or any high-traffic plugin breaks | EXECUTE TASK 12 (rollback), then debug |
|
||||
| Engine won't stay up (crashloop) | EXECUTE TASK 12 immediately, investigate logs |
|
||||
|
||||
The threshold for rollback is qualitative — your call. The intent is enforcement-on by default; rollback should be the exception.
|
||||
|
||||
---
|
||||
|
||||
## Task 12: Rollback procedure (conditional — only if Task 11 says so)
|
||||
|
||||
**Files:** none. Coolify state restoration.
|
||||
|
||||
- [ ] **Step 1: Re-enable bypass on the data engine**
|
||||
|
||||
```powershell
|
||||
coolify env set wwv-data-engine WWV_SKIP_WS_AUTH=true
|
||||
```
|
||||
|
||||
- [ ] **Step 2: Restore (or unset) `JWKS_URL` to baseline value**
|
||||
|
||||
Open `C:\Users\silve\.claude\plans\coolify-baseline-<...>.md` and use the recorded value:
|
||||
|
||||
```powershell
|
||||
# If baseline value was "(unset)":
|
||||
coolify env unset wwv-data-engine JWKS_URL
|
||||
|
||||
# If baseline had a value:
|
||||
coolify env set wwv-data-engine JWKS_URL=<baseline value>
|
||||
```
|
||||
|
||||
- [ ] **Step 3: Restore (or unset) `NEXT_PUBLIC_WWV_TICKET_AUTH_PLUGINS` to baseline value**
|
||||
|
||||
```powershell
|
||||
# If baseline was "(unset)":
|
||||
coolify env unset wwv NEXT_PUBLIC_WWV_TICKET_AUTH_PLUGINS
|
||||
|
||||
# If baseline had a value:
|
||||
coolify env set wwv NEXT_PUBLIC_WWV_TICKET_AUTH_PLUGINS=<baseline value>
|
||||
```
|
||||
|
||||
- [ ] **Step 4: Trigger both redeploys**
|
||||
|
||||
```powershell
|
||||
coolify deploy trigger wwv-data-engine
|
||||
coolify deploy trigger wwv
|
||||
coolify deploy status wwv-data-engine --watch
|
||||
coolify deploy status wwv --watch
|
||||
```
|
||||
|
||||
- [ ] **Step 5: Confirm rollback via the same smoke as Task 9**
|
||||
|
||||
```powershell
|
||||
pnpm dlx wscat -c wss://dataenginev2.worldwideview.dev/stream
|
||||
# Send: {"action":"subscribe","pluginId":"earthquakes"}
|
||||
```
|
||||
|
||||
Expected: connection stays open, data arrives WITHOUT sending an auth message. That's the pre-cutover bypass behavior restored.
|
||||
|
||||
- [ ] **Step 6: Document the rollback**
|
||||
|
||||
Append to the baseline file:
|
||||
|
||||
```markdown
|
||||
## Rollback executed <ISO timestamp>
|
||||
- Trigger: <what broke — e.g. "Earthquakes 4003 close in production browser test">
|
||||
- Plugins broken: <list>
|
||||
- Next steps: <e.g. "Investigate WsClient auth path for plugin X — file issue">
|
||||
```
|
||||
|
||||
STOP. Do not retry the cutover until the root cause is fixed and re-tested locally.
|
||||
|
||||
---
|
||||
|
||||
## Task 13: Mark Phase 4 complete (happy path only)
|
||||
|
||||
**Files:**
|
||||
- Modify: `worldwideview/docs/architecture/decisions/adr-0001-decentralized-plugin-auth.md` (or wherever ADR-001B lives)
|
||||
- Modify: any Northstar Sequence tracker doc (likely in `worldwideview/docs/` or `.agents/context/`)
|
||||
|
||||
- [ ] **Step 1: Find the ADR**
|
||||
|
||||
```powershell
|
||||
cd C:\dev\wwv\worldwideview
|
||||
cymbal search --text "ADR-001B"
|
||||
# OR
|
||||
Get-ChildItem -Recurse docs/architecture -Filter "adr-0001*.md"
|
||||
```
|
||||
|
||||
- [ ] **Step 2: Update the ADR status from "Proposed" to "Accepted"**
|
||||
|
||||
Edit the relevant ADR — typically there's a status block near the top:
|
||||
|
||||
```diff
|
||||
-Status: Proposed
|
||||
+Status: Accepted (cutover completed <YYYY-MM-DD>)
|
||||
```
|
||||
|
||||
- [ ] **Step 3: Find and update the Northstar Sequence tracker**
|
||||
|
||||
```powershell
|
||||
cymbal search --text "Northstar Sequence"
|
||||
# OR
|
||||
Grep --pattern "Phase 4" docs/
|
||||
```
|
||||
|
||||
Update Phase 4's status from in-progress to complete. Add a one-line note referencing the cutover date.
|
||||
|
||||
- [ ] **Step 4: Commit on a new branch**
|
||||
|
||||
```powershell
|
||||
git checkout main
|
||||
git pull --ff-only origin main
|
||||
git checkout -b docs/phase4-cutover-complete
|
||||
git add docs/
|
||||
git commit -m "docs: mark ADR-001B accepted and Northstar Phase 4 complete
|
||||
|
||||
Production data engine cutover completed <YYYY-MM-DD>. WebSocket JWT
|
||||
enforcement active for: <list from allowlist>. Local + production E2E
|
||||
verified. Baseline + allowlist files retained in personal notes."
|
||||
git push -u origin docs/phase4-cutover-complete
|
||||
gh pr create --title "docs: mark Phase 4 Coolify cutover complete" --body "Status update only — production cutover landed <YYYY-MM-DD>. See plan at .claude/plans/2026-05-24-phase4-coolify-cutover.md."
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Verification — end-to-end
|
||||
|
||||
After Task 13 (or Task 12 if rolled back):
|
||||
|
||||
1. **If happy path:** the WebSocket `/stream` endpoint rejects unauthenticated connections with `4003` (proven via wscat in Task 9), accepts authenticated UI sessions (proven in Task 10), shows earthquake markers and every other allowlisted plugin's data on the globe.
|
||||
2. **If rolled back:** the baseline file documents what broke. A follow-up plan is needed to fix the broken plugin(s) before re-attempting cutover. The system is back to "auth disabled" — same security posture as before this plan started, no production regression.
|
||||
|
||||
The Coolify dashboard should show both services healthy and the deploy timestamps should match the cutover window.
|
||||
|
||||
---
|
||||
|
||||
## Out of scope (separate plans / future work)
|
||||
|
||||
- **Port-5000 codification** (engine startup warning + ADR) — purely local DX, not cutover-blocking.
|
||||
- **`better-sqlite3` → `node:sqlite` refactor of `seeder-sdk`** — Docker prebuilt binaries make this non-urgent for production; local-dev DX only.
|
||||
- **Silent auth logging fixes** — engine should log `[WS] Closing unauthenticated connection from <ip>: <reason>` and use a more specific close reason than `"Invalid auth message"`. Improves operator UX; track as a small follow-up issue.
|
||||
- **Plugin `streamUrl` hardcoding sweep** — plugins still hardcode `wss://dataenginev2.worldwideview.dev/stream`; saved today by local-first routing in `resolveEngineUrl.ts`. Worth a sweep, not cutover-blocking.
|
||||
- **Northstar Sequence Phase 5** — final cutover (link nav, docs, marketing) — starts after Phase 4 is stable in production for ~1 week.
|
||||
- **Multi-engine audience separation** — currently every JWT has audience `wwv-data-engine` (broadcast). Per-engine audiences are a future ADR-001 follow-up.
|
||||
|
||||
---
|
||||
|
||||
## Assumptions
|
||||
|
||||
1. The Coolify CLI is installed and the `wwv` context is pre-configured (per personal memory). If not, fall back to the Coolify web dashboard for the same actions — the env-set + deploy-trigger workflow is identical, just clicked instead of typed.
|
||||
2. The production data engine URL is `https://dataenginev2.worldwideview.dev`. If it's something different, substitute throughout.
|
||||
3. The production marketplace URL is `https://marketplace.worldwideview.dev`. Confirmed in Task 2.
|
||||
4. The production frontend URL is `https://worldwideview.dev`. If it's `app.worldwideview.dev` or similar, substitute in Task 10.
|
||||
5. The data engine reads `JWKS_URL` at boot — confirmed via `startup-checks.ts` in PR #10. The cutover redeploy triggers a fresh boot.
|
||||
6. The frontend reads `NEXT_PUBLIC_*` vars at BUILD time — Coolify's `deploy trigger wwv` does a rebuild, so the new env var is baked into the bundle.
|
||||
7. The PKCE flow has already been used at least once on the production marketplace by an actual user, so `MarketplaceCredential` rows exist for that user. If you're testing as a fresh user, you'll need to complete `/api/marketplace/connect` once before Task 10 Step 3 — otherwise `/api/auth/ticket` will fail with "no marketplace credential."
|
||||
8. Coolify deploys complete in under ~5 minutes typical. If much longer, check the Coolify host disk space — per deployment rules, builds silently die when disk fills up.
|
||||
+7
-9
@@ -1,7 +1,7 @@
|
||||
import nextCoreWebVitals from "eslint-config-next/core-web-vitals";
|
||||
import nextTypeScript from "eslint-config-next/typescript";
|
||||
|
||||
export default [
|
||||
const config = [
|
||||
{
|
||||
ignores: [
|
||||
"node_modules/**",
|
||||
@@ -16,6 +16,8 @@ export default [
|
||||
"local-seeders/**",
|
||||
".agents/**",
|
||||
".claude/**",
|
||||
".gemini/**",
|
||||
"*.cjs",
|
||||
],
|
||||
},
|
||||
...nextCoreWebVitals,
|
||||
@@ -33,20 +35,16 @@ export default [
|
||||
|
||||
// Pre-existing — flagged in the original code review (#96):
|
||||
"@typescript-eslint/no-explicit-any": "warn",
|
||||
"no-console": "warn",
|
||||
"no-console": "off",
|
||||
|
||||
// React 19 hook-purity rules from eslint-plugin-react-hooks 7+:
|
||||
"react-hooks/purity": "warn",
|
||||
"react-hooks/refs": "warn",
|
||||
"react-hooks/set-state-in-effect": "warn",
|
||||
"react-hooks/immutability": "warn",
|
||||
"react-hooks/static-components": "warn",
|
||||
|
||||
// (These were previously hallucinated or require extra plugins)
|
||||
// Misc one-offs across the codebase:
|
||||
"react/no-unescaped-entities": "warn",
|
||||
"@typescript-eslint/ban-ts-comment": "warn",
|
||||
"@next/next/no-assign-module-variable": "warn",
|
||||
"prefer-const": "warn",
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
export default config;
|
||||
+25
-2
@@ -19,6 +19,7 @@ const nextConfig: NextConfig = {
|
||||
async headers() {
|
||||
return [
|
||||
{
|
||||
// Global security headers for all routes
|
||||
source: "/(.*)",
|
||||
headers: [
|
||||
{
|
||||
@@ -51,6 +52,30 @@ const nextConfig: NextConfig = {
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
// Camera proxy routes serve content that must be embeddable in an <iframe>
|
||||
// within the same origin. Override the global frame-ancestors 'none' and
|
||||
// X-Frame-Options: DENY so the browser allows the proxy response to be
|
||||
// framed by our own app (localhost:3000 / production domain).
|
||||
// The upstream camera HTML already had its own X-Frame-Options stripped by
|
||||
// the iframe proxy route; this override ensures our response headers don't
|
||||
// re-block it.
|
||||
source: "/api/camera/proxy/:path*",
|
||||
headers: [
|
||||
{
|
||||
key: "Content-Security-Policy",
|
||||
// Proxy routes serve arbitrary external HTML (YouTube embeds, camera feeds, etc.).
|
||||
// Restricting style-src/script-src here would break the proxied content since we
|
||||
// cannot predict which CDN domains it loads from. The meaningful security boundary
|
||||
// is frame-ancestors 'self' — only our own origin can embed these proxy responses.
|
||||
value: "default-src * 'unsafe-inline' 'unsafe-eval' data: blob:; frame-ancestors 'self'",
|
||||
},
|
||||
// Remove the DENY override — SAMEORIGIN allows our app to frame this response
|
||||
{ key: "X-Frame-Options", value: "SAMEORIGIN" },
|
||||
{ key: "X-Content-Type-Options", value: "nosniff" },
|
||||
{ key: "Referrer-Policy", value: "strict-origin-when-cross-origin" },
|
||||
],
|
||||
},
|
||||
];
|
||||
},
|
||||
|
||||
@@ -93,6 +118,4 @@ const nextConfig: NextConfig = {
|
||||
},
|
||||
};
|
||||
|
||||
import { withSentryConfig } from "@sentry/nextjs";
|
||||
|
||||
export default nextConfig;
|
||||
+19
-18
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "worldwideview",
|
||||
"version": "2.15.5",
|
||||
"version": "2.24.4",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"packageManager": "[email protected]",
|
||||
@@ -31,10 +31,10 @@
|
||||
"@prisma/adapter-pg": "^7.8.0",
|
||||
"@prisma/client": "^7.8.0",
|
||||
"@prisma/client-runtime-utils": "7.8.0",
|
||||
"@sentry/nextjs": "^10.52.0",
|
||||
"@supabase/supabase-js": "^2.105.4",
|
||||
"@sentry/nextjs": "^10.54.0",
|
||||
"@supabase/ssr": "^0.10.3",
|
||||
"@supabase/supabase-js": "^2.106.2",
|
||||
"@types/pg": "^8.20.0",
|
||||
"@vercel/analytics": "^1.6.1",
|
||||
"@worldwideview/wwv-plugin-sdk": "workspace:*",
|
||||
"bcryptjs": "^3.0.3",
|
||||
"cesium": "^1.141.0",
|
||||
@@ -42,21 +42,21 @@
|
||||
"hls.js": "^1.6.16",
|
||||
"insecam-api": "^0.0.3",
|
||||
"jose": "^6.2.3",
|
||||
"lucide-react": "^1.14.0",
|
||||
"lucide-react": "^1.17.0",
|
||||
"next": "16.2.6",
|
||||
"next-auth": "^5.0.0-beta.30",
|
||||
"openid-client": "^6.8.4",
|
||||
"pg": "^8.20.0",
|
||||
"pg": "^8.21.0",
|
||||
"prisma": "^7.8.0",
|
||||
"react": "19.2.6",
|
||||
"react-dom": "19.2.6",
|
||||
"react-player": "^3.4.0",
|
||||
"resium": "1.21.0",
|
||||
"satellite.js": "^7.0.0",
|
||||
"stripe": "^22.1.1",
|
||||
"resium": "1.21.1",
|
||||
"satellite.js": "^7.0.1",
|
||||
"stripe": "^22.2.0",
|
||||
"tslib": "^2.8.1",
|
||||
"undici": "^8.2.0",
|
||||
"ws": "^8.14.2",
|
||||
"undici": "^8.3.0",
|
||||
"ws": "^8.21.0",
|
||||
"zod": "^4.4.3",
|
||||
"zustand": "^5.0.13"
|
||||
},
|
||||
@@ -74,10 +74,10 @@
|
||||
"@types/react": "^19",
|
||||
"@types/react-dom": "^19",
|
||||
"@types/ws": "^8.18.1",
|
||||
"@typescript-eslint/eslint-plugin": "^8.59.3",
|
||||
"@typescript-eslint/parser": "^8.59.3",
|
||||
"@vitejs/plugin-react": "^5.1.4",
|
||||
"@vitest/coverage-v8": "4.1.6",
|
||||
"@typescript-eslint/eslint-plugin": "^8.60.0",
|
||||
"@typescript-eslint/parser": "^8.60.0",
|
||||
"@vitejs/plugin-react": "^6.0.2",
|
||||
"@vitest/coverage-v8": "4.1.7",
|
||||
"concurrently": "^9.2.1",
|
||||
"copy-webpack-plugin": "^14.0.0",
|
||||
"eslint": "^9",
|
||||
@@ -92,10 +92,10 @@
|
||||
"jsdom": "^28.1.0",
|
||||
"rollup-plugin-external-globals": "^0.13.0",
|
||||
"tree-kill": "^1.2.2",
|
||||
"tsx": "^4.21.0",
|
||||
"tsx": "^4.22.3",
|
||||
"typescript": "^5",
|
||||
"vite": "^8.0.12",
|
||||
"vitest": "^4.1.6"
|
||||
"vite": "^8.0.14",
|
||||
"vitest": "^4.1.7"
|
||||
},
|
||||
"pnpm": {
|
||||
"overrides": {
|
||||
@@ -120,3 +120,4 @@
|
||||
"pnpm": ">=9.0.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,11 +13,11 @@
|
||||
"clean": "rm -rf dist"
|
||||
},
|
||||
"dependencies": {
|
||||
"commander": "^12.1.0",
|
||||
"commander": "^14.0.3",
|
||||
"prompts": "^2.4.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^20.0.0",
|
||||
"@types/node": "^25.9.1",
|
||||
"@types/prompts": "^2.4.9",
|
||||
"typescript": "^5.0.0"
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
/* eslint-disable no-console */
|
||||
import { Command } from 'commander';
|
||||
import { saveConfig } from '../utils/config.js';
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
/* eslint-disable no-console */
|
||||
import { Command } from 'commander';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
/* eslint-disable no-console */
|
||||
import { Command } from 'commander';
|
||||
import { execSync } from 'child_process';
|
||||
import path from 'path';
|
||||
@@ -50,7 +51,7 @@ export const publishCommand = new Command('publish')
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
let originalName = pkgContent.name;
|
||||
const originalName = pkgContent.name;
|
||||
let publishedName = originalName;
|
||||
|
||||
// Determine organization
|
||||
@@ -66,7 +67,7 @@ export const publishCommand = new Command('publish')
|
||||
try {
|
||||
const whoami = execSync('npm whoami', { stdio: 'pipe' }).toString().trim();
|
||||
targetOrg = whoami;
|
||||
} catch (e) {
|
||||
} catch (_e) {
|
||||
// Not logged in or errored, ignore
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@worldwideview/wwv-lib-incidents",
|
||||
"version": "1.0.2",
|
||||
"version": "1.0.4",
|
||||
"description": "Shared abstract base classes for WorldWideView incident plugins (earthquakes, wildfires, conflicts)",
|
||||
"main": "src/index.ts",
|
||||
"types": "src/index.ts",
|
||||
|
||||
@@ -0,0 +1,283 @@
|
||||
/**
|
||||
* Guard tests for the BaseIncidentPlugin WebSocket payload contract.
|
||||
*
|
||||
* CONTEXT — The bug this suite guards against (now fixed):
|
||||
* WsClient.handleDataMessage (src/core/data/WsClient.ts, lines 166-190) has three branches:
|
||||
* 1. Plugin has `mapWebsocketPayload` → called with raw payload → must return GeoEntity[]
|
||||
* 2. No handler AND payload IS a flat array → used directly (timestamps normalised)
|
||||
* 3. No handler AND payload is ANY OTHER object → silently dropped (console.warn + return)
|
||||
*
|
||||
* BaseIncidentPlugin now provides a default `mapWebsocketPayload` that unwraps the three
|
||||
* common payload shapes (scheduler envelope, GeoJSON FeatureCollection, flat array).
|
||||
* Subclasses may override for domain-specific shapes.
|
||||
*/
|
||||
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { BaseIncidentPlugin } from "./index";
|
||||
import type {
|
||||
GeoEntity,
|
||||
TimeRange,
|
||||
ServerPluginConfig,
|
||||
FilterDefinition,
|
||||
PluginCategory,
|
||||
CesiumEntityOptions,
|
||||
} from "@worldwideview/wwv-plugin-sdk";
|
||||
|
||||
// ─── Minimal GeoEntity factory ────────────────────────────────────────────────
|
||||
|
||||
function makeEntity(id: string, overrides: Partial<GeoEntity> = {}): GeoEntity {
|
||||
return {
|
||||
id,
|
||||
pluginId: "test-incident-plugin",
|
||||
latitude: 35.6762,
|
||||
longitude: 139.6503,
|
||||
timestamp: new Date("2025-01-01T00:00:00Z"),
|
||||
properties: {},
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
// ─── Minimal concrete subclass ────────────────────────────────────────────────
|
||||
// We keep it as bare-bones as possible — only the abstract members required to
|
||||
// instantiate the class. We do NOT add mapWebsocketPayload here, so we're testing
|
||||
// the BaseIncidentPlugin base behaviour exactly.
|
||||
|
||||
class MinimalIncidentPlugin extends BaseIncidentPlugin {
|
||||
id = "test-incident-plugin";
|
||||
name = "Test Incident Plugin";
|
||||
description = "Test";
|
||||
icon = null;
|
||||
category: PluginCategory = "natural-disaster";
|
||||
version = "0.0.1";
|
||||
|
||||
async fetch(_timeRange: TimeRange): Promise<GeoEntity[]> {
|
||||
return [];
|
||||
}
|
||||
|
||||
getServerConfig(): ServerPluginConfig {
|
||||
return {
|
||||
apiBasePath: "/api/test-incident-plugin",
|
||||
streamUrl: "ws://localhost:5001/stream",
|
||||
pollingIntervalMs: 0,
|
||||
};
|
||||
}
|
||||
|
||||
getFilterDefinitions(): FilterDefinition[] {
|
||||
return [];
|
||||
}
|
||||
|
||||
getLegend(): { label: string; color: string; filterId?: string; filterValue?: string }[] {
|
||||
return [];
|
||||
}
|
||||
|
||||
protected getSeverityValue(_entity: GeoEntity): number {
|
||||
return 0;
|
||||
}
|
||||
|
||||
protected getSeverityColor(_value: number): string {
|
||||
return "#ef4444";
|
||||
}
|
||||
|
||||
protected getSeveritySize(_value: number): number {
|
||||
return 10;
|
||||
}
|
||||
}
|
||||
|
||||
// ─── Subclass that DOES override mapWebsocketPayload ─────────────────────────
|
||||
|
||||
const FIXED_ENTITIES = [makeEntity("override-1"), makeEntity("override-2")];
|
||||
|
||||
class OverridingIncidentPlugin extends MinimalIncidentPlugin {
|
||||
id = "overriding-incident-plugin";
|
||||
|
||||
mapWebsocketPayload(_payload: unknown, _existingEntities?: GeoEntity[]): GeoEntity[] {
|
||||
return FIXED_ENTITIES;
|
||||
}
|
||||
}
|
||||
|
||||
// ─── Helpers that mimic WsClient.handleDataMessage branching logic ────────────
|
||||
// We test the plugin method in isolation (unit test), not the full WsClient,
|
||||
// because WsClient has DOM/Zustand/DataBus dependencies. This mirrors the exact
|
||||
// logic from WsClient lines 172-182.
|
||||
|
||||
function simulateWsClientDispatch(
|
||||
plugin: BaseIncidentPlugin,
|
||||
rawPayload: unknown
|
||||
): GeoEntity[] | null {
|
||||
if (typeof (plugin as any).mapWebsocketPayload === "function") {
|
||||
return (plugin as any).mapWebsocketPayload(rawPayload, []);
|
||||
}
|
||||
if (!Array.isArray(rawPayload)) {
|
||||
// This is the silent-drop branch — return null to signal "dropped"
|
||||
return null;
|
||||
}
|
||||
return (rawPayload as GeoEntity[]).map((e) => ({
|
||||
...e,
|
||||
timestamp: new Date(e.timestamp || Date.now()),
|
||||
}));
|
||||
}
|
||||
|
||||
// ─── Test suite ───────────────────────────────────────────────────────────────
|
||||
|
||||
describe("BaseIncidentPlugin — WebSocket payload contract", () => {
|
||||
|
||||
describe("scheduler-wrapped payload { source, fetchedAt, items, totalCount }", () => {
|
||||
it(
|
||||
"unwraps { source, fetchedAt, items, totalCount } and returns items as GeoEntity[]",
|
||||
() => {
|
||||
const plugin = new MinimalIncidentPlugin();
|
||||
const entity1 = makeEntity("eq-1");
|
||||
const entity2 = makeEntity("eq-2");
|
||||
|
||||
const wrappedPayload = {
|
||||
source: "usgs-earthquake-feed",
|
||||
fetchedAt: "2025-01-01T00:00:00Z",
|
||||
items: [entity1, entity2],
|
||||
totalCount: 2,
|
||||
};
|
||||
|
||||
// After the fix: mapWebsocketPayload should exist and return both entities
|
||||
const result = simulateWsClientDispatch(plugin, wrappedPayload);
|
||||
|
||||
expect(result).not.toBeNull();
|
||||
expect(Array.isArray(result)).toBe(true);
|
||||
expect(result).toHaveLength(2);
|
||||
expect(result![0].id).toBe("eq-1");
|
||||
expect(result![1].id).toBe("eq-2");
|
||||
}
|
||||
);
|
||||
|
||||
});
|
||||
|
||||
describe("flat GeoEntity[] payload", () => {
|
||||
/**
|
||||
* Flat arrays bypass mapWebsocketPayload entirely in WsClient — they work today.
|
||||
* This test MUST stay green before and after the fix.
|
||||
*/
|
||||
it("passes flat GeoEntity[] through unchanged (current working behaviour)", () => {
|
||||
const plugin = new MinimalIncidentPlugin();
|
||||
const entities = [makeEntity("eq-flat-1"), makeEntity("eq-flat-2")];
|
||||
|
||||
const result = simulateWsClientDispatch(plugin, entities);
|
||||
|
||||
expect(result).not.toBeNull();
|
||||
expect(result).toHaveLength(2);
|
||||
expect(result![0].id).toBe("eq-flat-1");
|
||||
expect(result![1].id).toBe("eq-flat-2");
|
||||
});
|
||||
|
||||
it("normalises timestamp strings to Date objects for flat array payloads", () => {
|
||||
const plugin = new MinimalIncidentPlugin();
|
||||
const raw = [{
|
||||
...makeEntity("eq-ts-1"),
|
||||
// Simulate a timestamp that arrives over the wire as a string
|
||||
timestamp: "2025-06-01T12:00:00Z" as unknown as Date,
|
||||
}];
|
||||
|
||||
const result = simulateWsClientDispatch(plugin, raw);
|
||||
|
||||
expect(result).not.toBeNull();
|
||||
expect(result![0].timestamp).toBeInstanceOf(Date);
|
||||
});
|
||||
});
|
||||
|
||||
describe("GeoJSON { features: [...] } payload", () => {
|
||||
it(
|
||||
"normalises a GeoJSON FeatureCollection into GeoEntity[]",
|
||||
() => {
|
||||
const plugin = new MinimalIncidentPlugin();
|
||||
|
||||
const geojsonPayload = {
|
||||
type: "FeatureCollection",
|
||||
features: [
|
||||
{
|
||||
type: "Feature",
|
||||
geometry: { type: "Point", coordinates: [139.65, 35.68] },
|
||||
properties: { id: "gj-1", magnitude: 4.5 },
|
||||
},
|
||||
{
|
||||
type: "Feature",
|
||||
geometry: { type: "Point", coordinates: [135.50, 34.69] },
|
||||
properties: { id: "gj-2", magnitude: 3.1 },
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const result = simulateWsClientDispatch(plugin, geojsonPayload);
|
||||
|
||||
expect(result).not.toBeNull();
|
||||
expect(Array.isArray(result)).toBe(true);
|
||||
expect(result).toHaveLength(2);
|
||||
// Each feature should have been converted to a GeoEntity with lat/lon
|
||||
expect(result![0].latitude).toBeCloseTo(35.68, 2);
|
||||
expect(result![0].longitude).toBeCloseTo(139.65, 2);
|
||||
}
|
||||
);
|
||||
|
||||
});
|
||||
|
||||
describe("subclass override of mapWebsocketPayload", () => {
|
||||
/**
|
||||
* A subclass that implements mapWebsocketPayload is handled correctly TODAY.
|
||||
* This covers the "conflict-events" / "iranwarlive" pattern and must stay green.
|
||||
*/
|
||||
it("calls the subclass override and returns its result regardless of payload shape", () => {
|
||||
const plugin = new OverridingIncidentPlugin();
|
||||
|
||||
// Even if the payload is an object (which would normally be dropped), the
|
||||
// subclass override is respected.
|
||||
const wrappedPayload = {
|
||||
source: "conflict-api",
|
||||
fetchedAt: "2025-01-01T00:00:00Z",
|
||||
items: [makeEntity("conflict-1")],
|
||||
totalCount: 1,
|
||||
};
|
||||
|
||||
const result = simulateWsClientDispatch(plugin, wrappedPayload);
|
||||
|
||||
// Should return the overriding subclass's fixed result, not the raw items
|
||||
expect(result).toStrictEqual(FIXED_ENTITIES);
|
||||
});
|
||||
|
||||
it("override is also called for flat array payloads, taking precedence over default handling", () => {
|
||||
const plugin = new OverridingIncidentPlugin();
|
||||
const flatPayload = [makeEntity("flat-1"), makeEntity("flat-2"), makeEntity("flat-3")];
|
||||
|
||||
const result = simulateWsClientDispatch(plugin, flatPayload);
|
||||
|
||||
// The override always wins — result is FIXED_ENTITIES, not the 3-element flat array
|
||||
expect(result).toStrictEqual(FIXED_ENTITIES);
|
||||
expect(result).toHaveLength(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe("BaseIncidentPlugin structural contract", () => {
|
||||
it("has mapWebsocketPayload defined", () => {
|
||||
const plugin = new MinimalIncidentPlugin();
|
||||
expect(typeof (plugin as any).mapWebsocketPayload).toBe("function");
|
||||
});
|
||||
|
||||
it("implements the required WorldPlugin lifecycle methods", () => {
|
||||
const plugin = new MinimalIncidentPlugin();
|
||||
expect(typeof plugin.initialize).toBe("function");
|
||||
expect(typeof plugin.destroy).toBe("function");
|
||||
expect(typeof plugin.fetch).toBe("function");
|
||||
expect(typeof plugin.getPollingInterval).toBe("function");
|
||||
expect(typeof plugin.getLayerConfig).toBe("function");
|
||||
expect(typeof plugin.renderEntity).toBe("function");
|
||||
});
|
||||
|
||||
it("returns polling interval of 0 (WebSocket-only mode)", () => {
|
||||
const plugin = new MinimalIncidentPlugin();
|
||||
expect(plugin.getPollingInterval()).toBe(0);
|
||||
});
|
||||
|
||||
it("returns default layer config with clustering enabled", () => {
|
||||
const plugin = new MinimalIncidentPlugin();
|
||||
const config = plugin.getLayerConfig();
|
||||
expect(config.clusterEnabled).toBe(true);
|
||||
expect(config.color).toBe("#ef4444");
|
||||
expect(typeof config.clusterDistance).toBe("number");
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -80,4 +80,69 @@ export abstract class BaseIncidentPlugin implements WorldPlugin {
|
||||
labelFont: "11px JetBrains Mono, monospace" // Adds optional label standard
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Default WebSocket payload normaliser. WsClient calls this when a data message
|
||||
* arrives; if absent, WsClient silently drops anything that isn't a flat array.
|
||||
*
|
||||
* Handles three shapes:
|
||||
* - Scheduler envelope: { source, fetchedAt, items: GeoEntity[], totalCount } → items
|
||||
* - GeoJSON FeatureCollection: { features: [{geometry, properties}, ...] } → normalised
|
||||
* - Flat array: passes through (with timestamp normalisation)
|
||||
*
|
||||
* Subclasses may override for domain-specific shapes; this default covers
|
||||
* the common scheduler-wrapped and GeoJSON cases so the bug doesn't recur.
|
||||
*
|
||||
* @param payload - Raw payload received from the WebSocket message
|
||||
* @param _existingEntities - Current entities in the layer (unused by default; available for subclass merging logic)
|
||||
* @returns Normalised GeoEntity[] ready for the layer renderer
|
||||
*/
|
||||
mapWebsocketPayload(payload: any, _existingEntities?: GeoEntity[]): GeoEntity[] {
|
||||
const items = this.extractIncidentItems(payload);
|
||||
return items.map((e) => ({
|
||||
...e,
|
||||
timestamp: e.timestamp instanceof Date ? e.timestamp : new Date(e.timestamp ?? Date.now()),
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts a raw GeoEntity array from the three common payload shapes:
|
||||
* scheduler envelope, GeoJSON FeatureCollection, or flat array.
|
||||
*
|
||||
* @param payload - The raw WebSocket payload
|
||||
* @returns Unnormalised array of GeoEntity-like objects (timestamps not yet coerced)
|
||||
*/
|
||||
protected extractIncidentItems(payload: any): GeoEntity[] {
|
||||
if (Array.isArray(payload)) {
|
||||
return payload as GeoEntity[];
|
||||
}
|
||||
if (payload && Array.isArray(payload.items)) {
|
||||
return payload.items as GeoEntity[];
|
||||
}
|
||||
if (payload && Array.isArray(payload.features)) {
|
||||
return payload.features.map((f: any, i: number) => this.geoJsonFeatureToEntity(f, i));
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a GeoJSON Feature object into a GeoEntity.
|
||||
*
|
||||
* @param feature - GeoJSON Feature with geometry.coordinates and optional properties
|
||||
* @param index - Position in the parent features array, used to generate a fallback id
|
||||
* @returns A GeoEntity with lat/lon extracted from the feature geometry
|
||||
*/
|
||||
protected geoJsonFeatureToEntity(feature: any, index: number): GeoEntity {
|
||||
const coords = feature?.geometry?.coordinates ?? [0, 0];
|
||||
const props = feature?.properties ?? {};
|
||||
return {
|
||||
id: props.id ?? `${this.id}-${index}`,
|
||||
pluginId: this.id,
|
||||
latitude: coords[1],
|
||||
longitude: coords[0],
|
||||
timestamp: props.timestamp ? new Date(props.timestamp) : new Date(),
|
||||
properties: props,
|
||||
label: props.label,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,11 @@
|
||||
|
||||
import { describe, it, expectTypeOf } from "vitest";
|
||||
import type {
|
||||
TokenExchangeRequest,
|
||||
TokenExchangeResponse,
|
||||
import type {
|
||||
TokenExchangeRequest,
|
||||
TokenExchangeResponse,
|
||||
WebSocketAuthMessage,
|
||||
SensitiveString,
|
||||
PluginTicket,
|
||||
Tier,
|
||||
PKCEConnectRequest,
|
||||
PKCETokenExchange,
|
||||
@@ -21,7 +23,8 @@ describe("Auth Contracts", () => {
|
||||
expectTypeOf<TokenExchangeRequest>().toHaveProperty("audience").toEqualTypeOf<string>();
|
||||
|
||||
// @ts-expect-error - missing required apiKey
|
||||
const badReq: TokenExchangeRequest = { audience: "engine-123" };
|
||||
const _badReq: TokenExchangeRequest = { audience: "engine-123" };
|
||||
void _badReq;
|
||||
});
|
||||
|
||||
it("TokenExchangeResponse has exact required properties", () => {
|
||||
@@ -31,19 +34,22 @@ describe("Auth Contracts", () => {
|
||||
expectTypeOf<TokenExchangeResponse>().toHaveProperty("tier").toEqualTypeOf<Tier | undefined>();
|
||||
|
||||
// @ts-expect-error - missing required token
|
||||
const badRes: TokenExchangeResponse = { expiresAt: 123456789, kid: "key-1" };
|
||||
const _badRes: TokenExchangeResponse = { expiresAt: 123456789, kid: "key-1" };
|
||||
void _badRes;
|
||||
});
|
||||
|
||||
it("WebSocketAuthMessage has exact required properties including protocol version", () => {
|
||||
expectTypeOf<WebSocketAuthMessage>().toHaveProperty("type").toEqualTypeOf<"auth">();
|
||||
expectTypeOf<WebSocketAuthMessage>().toHaveProperty("v").toEqualTypeOf<1>();
|
||||
expectTypeOf<WebSocketAuthMessage>().toHaveProperty("token").toEqualTypeOf<SensitiveString>();
|
||||
expectTypeOf<WebSocketAuthMessage>().toHaveProperty("token").toEqualTypeOf<PluginTicket>();
|
||||
|
||||
// @ts-expect-error - missing version
|
||||
const badMsg: WebSocketAuthMessage = { type: "auth", token: "jwt-token-here" as SensitiveString };
|
||||
const _badMsg: WebSocketAuthMessage = { type: "auth", token: "jwt-token-here" as SensitiveString };
|
||||
void _badMsg;
|
||||
|
||||
// @ts-expect-error - wrong version
|
||||
const badVersion: WebSocketAuthMessage = { type: "auth", v: 2, token: "jwt-token-here" as SensitiveString };
|
||||
const _badVersion: WebSocketAuthMessage = { type: "auth", v: 2, token: "jwt-token-here" as SensitiveString };
|
||||
void _badVersion;
|
||||
});
|
||||
|
||||
it("WebSocketMessage is a discriminated union correctly containing WebSocketAuthMessage", () => {
|
||||
|
||||
@@ -8,6 +8,12 @@
|
||||
*/
|
||||
export type SensitiveString = string & { readonly __brand: "SensitiveString" };
|
||||
|
||||
/** Marketplace session JWT issued after PKCE; scoped to this Local App only. */
|
||||
export type MarketplaceSessionToken = string & { readonly __brand: "marketplace-session" };
|
||||
|
||||
/** Short-lived, audience-bound JWT obtained from token exchange; used for WebSocket auth. */
|
||||
export type PluginTicket = string & { readonly __brand: "plugin-ticket" };
|
||||
|
||||
/**
|
||||
* Factory function to safely cast a string to a SensitiveString.
|
||||
* This provides a single grep target for every place a secret enters the system.
|
||||
@@ -66,7 +72,7 @@ export interface WebSocketAuthMessage {
|
||||
/** Protocol version to allow future wire shape evolution */
|
||||
v: 1;
|
||||
/** The short-lived JWT obtained from the Token Exchange */
|
||||
token: SensitiveString;
|
||||
token: PluginTicket;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+60
-8
@@ -1,4 +1,11 @@
|
||||
import { defineConfig, devices } from '@playwright/test';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
|
||||
const __dir = path.dirname(fileURLToPath(import.meta.url));
|
||||
const MARKETPLACE_DIR = path.resolve(__dir, '../worldwideview-marketplace');
|
||||
const hasMarketplace = fs.existsSync(MARKETPLACE_DIR);
|
||||
|
||||
/**
|
||||
* See https://playwright.dev/docs/test-configuration.
|
||||
@@ -11,6 +18,16 @@ export default defineConfig({
|
||||
globalSetup: './tests/global.setup.ts',
|
||||
globalTeardown: './tests/global.teardown.ts',
|
||||
testDir: './tests',
|
||||
// web-auth.spec.ts targets worldwideview-web (https://wwv.local:3001) — use playwright.web.config.ts
|
||||
// marketplace-from-instance.spec.ts uses playwright.marketplace.config.ts; full-flow requires marketplace repo
|
||||
// marketplace-redirect-handshake.spec.ts and marketplace-sign-out.spec.ts require marketplace.wwv.local:3002
|
||||
// — use playwright.cross-app.config.ts for these cross-origin handshake tests
|
||||
testIgnore: [
|
||||
'**/web-auth.spec.ts',
|
||||
'**/marketplace-from-instance.spec.ts',
|
||||
'**/marketplace-redirect-handshake.spec.ts',
|
||||
'**/marketplace-sign-out.spec.ts',
|
||||
],
|
||||
/* Run tests in files in parallel */
|
||||
fullyParallel: true,
|
||||
/* Fail the build on CI if you accidentally left test.only in the source code. */
|
||||
@@ -39,14 +56,49 @@ export default defineConfig({
|
||||
storageState: 'playwright/.auth/user.json'
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'firefox',
|
||||
use: {
|
||||
...devices['Desktop Firefox'],
|
||||
storageState: 'playwright/.auth/user.json',
|
||||
launchOptions: {
|
||||
firefoxUserPrefs: {
|
||||
// Disable MSAA/AT-SPI accessibility layer — causes hangs on Linux CI
|
||||
'accessibility.force_disabled': 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'webkit',
|
||||
use: {
|
||||
...devices['Desktop Safari'],
|
||||
storageState: 'playwright/.auth/user.json'
|
||||
},
|
||||
},
|
||||
],
|
||||
|
||||
/* Run your local dev server before starting the tests */
|
||||
webServer: {
|
||||
command: 'pnpm dev',
|
||||
env: { PORT: '3001' },
|
||||
url: 'http://localhost:3001',
|
||||
reuseExistingServer: !process.env.CI,
|
||||
timeout: 120 * 1000,
|
||||
},
|
||||
/* Run dev servers before starting the tests */
|
||||
webServer: [
|
||||
{
|
||||
command: 'pnpm dev',
|
||||
env: {
|
||||
PORT: '3001',
|
||||
NEXT_PUBLIC_MARKETPLACE_URL: 'http://localhost:3002',
|
||||
},
|
||||
url: 'http://localhost:3001',
|
||||
reuseExistingServer: !process.env.CI,
|
||||
timeout: 120 * 1000,
|
||||
},
|
||||
// Only start marketplace when the repo is checked out alongside worldwideview.
|
||||
// In CI the marketplace dir does not exist — omitting it prevents spawn ENOENT.
|
||||
...(hasMarketplace ? [{
|
||||
command: 'pnpm dev',
|
||||
cwd: MARKETPLACE_DIR,
|
||||
env: { PORT: '3002' },
|
||||
url: 'http://localhost:3002',
|
||||
reuseExistingServer: !process.env.CI,
|
||||
timeout: 120 * 1000,
|
||||
}] : []),
|
||||
],
|
||||
});
|
||||
@@ -0,0 +1,85 @@
|
||||
/**
|
||||
* Cross-app E2E config.
|
||||
* Starts both worldwideview-web (3001) and worldwideview-marketplace (3002)
|
||||
* and runs specs that exercise the shared Supabase cookie handshake across
|
||||
* the .wwv.local cookie domain.
|
||||
*
|
||||
* The marketplace MUST be reachable at https://marketplace.wwv.local:3002
|
||||
* (not localhost:3002) because the Supabase auth cookie is scoped to .wwv.local.
|
||||
*
|
||||
* Loads .env.test credentials via Node fs so specs can read them from
|
||||
* process.env without requiring a dotenv package install.
|
||||
*
|
||||
* Usage:
|
||||
* pnpm exec playwright test --config=playwright.cross-app.config.ts
|
||||
*/
|
||||
import { defineConfig, devices } from '@playwright/test';
|
||||
import path from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
import fs from 'fs';
|
||||
|
||||
const __dir = path.dirname(fileURLToPath(import.meta.url));
|
||||
const WEB_DIR = path.resolve(__dir, '../worldwideview-web');
|
||||
const MARKETPLACE_DIR = path.resolve(__dir, '../worldwideview-marketplace');
|
||||
|
||||
// Load .env.test credentials into process.env so specs can read them.
|
||||
// Uses fs directly to avoid a dotenv dependency.
|
||||
const envTestPath = path.resolve(__dir, '.env.test');
|
||||
if (fs.existsSync(envTestPath)) {
|
||||
const lines = fs.readFileSync(envTestPath, 'utf8').split('\n');
|
||||
for (const line of lines) {
|
||||
const trimmed = line.trim();
|
||||
if (!trimmed || trimmed.startsWith('#')) continue;
|
||||
const eqIdx = trimmed.indexOf('=');
|
||||
if (eqIdx === -1) continue;
|
||||
const key = trimmed.slice(0, eqIdx).trim();
|
||||
const val = trimmed.slice(eqIdx + 1).trim();
|
||||
if (key && !(key in process.env)) process.env[key] = val;
|
||||
}
|
||||
}
|
||||
|
||||
export default defineConfig({
|
||||
timeout: 60000,
|
||||
expect: { timeout: 10000 },
|
||||
testDir: './tests',
|
||||
testMatch: [
|
||||
'**/marketplace-redirect-handshake.spec.ts',
|
||||
'**/marketplace-sign-out.spec.ts',
|
||||
],
|
||||
fullyParallel: false,
|
||||
retries: 0,
|
||||
workers: 1,
|
||||
reporter: 'list',
|
||||
|
||||
use: {
|
||||
baseURL: 'https://marketplace.wwv.local:3002',
|
||||
ignoreHTTPSErrors: true,
|
||||
trace: 'on-first-retry',
|
||||
},
|
||||
|
||||
projects: [
|
||||
{
|
||||
name: 'chromium',
|
||||
use: { ...devices['Desktop Chrome'] },
|
||||
},
|
||||
],
|
||||
|
||||
webServer: [
|
||||
{
|
||||
command: 'pnpm dev',
|
||||
cwd: WEB_DIR,
|
||||
url: 'https://wwv.local:3001',
|
||||
reuseExistingServer: true,
|
||||
timeout: 90 * 1000,
|
||||
ignoreHTTPSErrors: true,
|
||||
},
|
||||
{
|
||||
command: 'pnpm dev',
|
||||
cwd: MARKETPLACE_DIR,
|
||||
url: 'https://marketplace.wwv.local:3002',
|
||||
reuseExistingServer: true,
|
||||
timeout: 90 * 1000,
|
||||
ignoreHTTPSErrors: true,
|
||||
},
|
||||
],
|
||||
});
|
||||
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
* Marketplace-only E2E config.
|
||||
* Runs against the marketplace dev server on port 3002 only.
|
||||
* No worldwideview auth or Docker/Postgres required.
|
||||
*
|
||||
* Usage:
|
||||
* pnpm exec playwright test --config=playwright.marketplace.config.ts
|
||||
*/
|
||||
import { defineConfig, devices } from '@playwright/test';
|
||||
import path from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
|
||||
const __dir = path.dirname(fileURLToPath(import.meta.url));
|
||||
const MARKETPLACE_DIR = path.resolve(__dir, '../worldwideview-marketplace');
|
||||
|
||||
export default defineConfig({
|
||||
timeout: 30000,
|
||||
expect: { timeout: 10000 },
|
||||
testDir: './tests',
|
||||
testMatch: '**/marketplace-from-instance.spec.ts',
|
||||
fullyParallel: false,
|
||||
retries: 0,
|
||||
workers: 1,
|
||||
reporter: 'list',
|
||||
|
||||
use: {
|
||||
baseURL: 'http://localhost:3002',
|
||||
trace: 'on-first-retry',
|
||||
},
|
||||
|
||||
projects: [
|
||||
{
|
||||
name: 'chromium',
|
||||
use: { ...devices['Desktop Chrome'] },
|
||||
},
|
||||
],
|
||||
|
||||
webServer: {
|
||||
command: 'pnpm dev',
|
||||
cwd: MARKETPLACE_DIR,
|
||||
env: { PORT: '3002' },
|
||||
url: 'http://localhost:3002',
|
||||
reuseExistingServer: true,
|
||||
timeout: 90 * 1000,
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* worldwideview-web E2E config.
|
||||
* Runs against the web dev server on https://wwv.local:3001.
|
||||
* Requires mkcert cert at worldwideview-web/certs/wwv.local+2.pem.
|
||||
*
|
||||
* Usage:
|
||||
* pnpm exec playwright test --config=playwright.web.config.ts
|
||||
*/
|
||||
import { defineConfig, devices } from '@playwright/test';
|
||||
import path from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
|
||||
const __dir = path.dirname(fileURLToPath(import.meta.url));
|
||||
const WEB_DIR = path.resolve(__dir, '../worldwideview-web');
|
||||
|
||||
export default defineConfig({
|
||||
timeout: 30000,
|
||||
expect: { timeout: 10000 },
|
||||
testDir: './tests',
|
||||
testMatch: '**/web-auth.spec.ts',
|
||||
fullyParallel: false,
|
||||
retries: 0,
|
||||
workers: 1,
|
||||
reporter: 'list',
|
||||
|
||||
use: {
|
||||
baseURL: 'https://wwv.local:3001',
|
||||
ignoreHTTPSErrors: true,
|
||||
trace: 'on-first-retry',
|
||||
},
|
||||
|
||||
projects: [
|
||||
{
|
||||
name: 'chromium',
|
||||
use: { ...devices['Desktop Chrome'] },
|
||||
},
|
||||
],
|
||||
|
||||
webServer: {
|
||||
command: 'pnpm dev',
|
||||
cwd: WEB_DIR,
|
||||
url: 'https://wwv.local:3001',
|
||||
reuseExistingServer: true,
|
||||
timeout: 90 * 1000,
|
||||
ignoreHTTPSErrors: true,
|
||||
},
|
||||
});
|
||||
Generated
+1846
-1379
File diff suppressed because it is too large.
Load diff
Binary file not shown.
|
After Width: | Height: | Size: 9.8 KiB |
+18
-3
@@ -63,7 +63,22 @@ console.log(`🔌 Assigned deterministic database port: ${port}`);
|
||||
|
||||
// Robust rewrite of DATABASE_URL in .env
|
||||
const envPath = path.resolve(cwd, '.env');
|
||||
if (fs.existsSync(envPath)) {
|
||||
|
||||
// Ensure .env exists — worktrees only have .env.local, not .env.
|
||||
// Without this, the DATABASE_URL injection block below is silently skipped
|
||||
// and safe-db-push.mjs fails with "DATABASE_URL is missing".
|
||||
if (!fs.existsSync(envPath)) {
|
||||
const examplePath = path.resolve(cwd, '.env.example');
|
||||
if (fs.existsSync(examplePath)) {
|
||||
fs.copyFileSync(examplePath, envPath);
|
||||
console.log('📄 Created .env from .env.example (worktree first-run).');
|
||||
} else {
|
||||
fs.writeFileSync(envPath, '');
|
||||
console.log('📄 Created empty .env (worktree first-run).');
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
const envContent = fs.readFileSync(envPath, 'utf8');
|
||||
const lines = envContent.split(/\r?\n/);
|
||||
|
||||
@@ -96,7 +111,7 @@ if (fs.existsSync(envPath)) {
|
||||
|
||||
if (linesModified) {
|
||||
const newContent = newLines.join('\n');
|
||||
|
||||
|
||||
// File write with retries and telemetry
|
||||
const maxRetries = 3;
|
||||
let attempt = 0;
|
||||
@@ -121,7 +136,7 @@ if (fs.existsSync(envPath)) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} // end DATABASE_URL injection block
|
||||
|
||||
|
||||
console.log('🚀 Checking local PostgreSQL database...');
|
||||
|
||||
@@ -15,7 +15,7 @@ function copyDir(src, dest) {
|
||||
}
|
||||
const entries = fs.readdirSync(src, { withFileTypes: true });
|
||||
|
||||
for (let entry of entries) {
|
||||
for (const entry of entries) {
|
||||
const srcPath = path.join(src, entry.name);
|
||||
const destPath = path.join(dest, entry.name);
|
||||
|
||||
|
||||
@@ -0,0 +1,391 @@
|
||||
#!/usr/bin/env node
|
||||
// gc-scan.mjs — deterministic garbage detection for the GC bot
|
||||
// Zero npm dependencies. Emits gc-findings.json consumed by the garbage-collector agent.
|
||||
//
|
||||
// Usage: node scripts/gc-scan.mjs [--out <path>] [--days-branch=90] [--days-comment=180]
|
||||
|
||||
import { execSync } from 'node:child_process';
|
||||
import { writeFileSync, readFileSync, existsSync } from 'node:fs';
|
||||
import { join, resolve, relative } from 'node:path';
|
||||
|
||||
const ROOT = process.cwd();
|
||||
|
||||
// Parse CLI args: --out <path>, --days-branch=N, --days-comment=N
|
||||
const ARGS = Object.fromEntries(
|
||||
process.argv.slice(2).flatMap(a => {
|
||||
const m = a.match(/^--([\w-]+)=(.+)$/);
|
||||
return m ? [[m[1], m[2]]] : [];
|
||||
})
|
||||
);
|
||||
const outIdx = process.argv.indexOf('--out');
|
||||
const OUT = outIdx !== -1 ? process.argv[outIdx + 1] : (ARGS['out'] ?? 'gc-findings.json');
|
||||
const STALE_BRANCH_DAYS = Number(ARGS['days-branch'] ?? 90);
|
||||
const STALE_COMMENT_DAYS = Number(ARGS['days-comment'] ?? 180);
|
||||
|
||||
/** @type {Array<Record<string, unknown>>} */
|
||||
const findings = [];
|
||||
|
||||
function run(cmd) {
|
||||
try {
|
||||
return execSync(cmd, { encoding: 'utf8', cwd: ROOT, stdio: ['pipe', 'pipe', 'pipe'] }).trim();
|
||||
} catch {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
function add(finding) {
|
||||
findings.push(finding);
|
||||
}
|
||||
|
||||
function daysAgo(isoDate) {
|
||||
if (!isoDate) return Infinity;
|
||||
return (Date.now() - new Date(isoDate).getTime()) / 86_400_000;
|
||||
}
|
||||
|
||||
// ─── Detector 1: Stale branches ──────────────────────────────────────────────
|
||||
function detectStaleBranches() {
|
||||
const out = run(
|
||||
'git for-each-ref --sort=committerdate refs/remotes/origin ' +
|
||||
'--format=%(refname:short)|%(committerdate:iso8601)|%(authorname)|%(subject)'
|
||||
);
|
||||
for (const line of out.split('\n').filter(Boolean)) {
|
||||
const [ref, date, author, subject] = line.split('|');
|
||||
const branch = ref.replace('origin/', '');
|
||||
if (['HEAD', 'main', 'master', 'develop'].includes(branch)) continue;
|
||||
const age = daysAgo(date);
|
||||
if (age < STALE_BRANCH_DAYS) continue;
|
||||
const mergeBase = run(`git merge-base origin/main "${ref}" 2>/dev/null`);
|
||||
const branchHead = run(`git rev-parse "${ref}"`);
|
||||
const isMerged = mergeBase === branchHead;
|
||||
add({
|
||||
type: 'stale-branch',
|
||||
tier: 'B',
|
||||
branch,
|
||||
author,
|
||||
lastCommitDate: date?.trim(),
|
||||
ageDays: Math.floor(age),
|
||||
isMerged,
|
||||
lastSubject: subject,
|
||||
description: `Branch '${branch}' is ${Math.floor(age)} days old${isMerged ? ' and fully merged into main — safe to delete' : ' with no recent activity'}`,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// ─── Detector 2: Stale TODO/FIXME/HACK comments ──────────────────────────────
|
||||
function detectStaleTodos() {
|
||||
const raw = run(
|
||||
'git grep -rn --fixed-strings -e "TODO" -e "FIXME" -e "HACK" -e "XXX" ' +
|
||||
'-- "*.ts" "*.tsx" "*.mjs" "*.js"'
|
||||
);
|
||||
if (!raw) return;
|
||||
|
||||
// Cap at 40 matches to keep git blame calls fast on large repos
|
||||
const lines = raw.split('\n').filter(Boolean).slice(0, 40);
|
||||
|
||||
for (const line of lines) {
|
||||
const firstColon = line.indexOf(':');
|
||||
if (firstColon === -1) continue;
|
||||
const afterFile = line.slice(firstColon + 1);
|
||||
const secondColon = afterFile.indexOf(':');
|
||||
if (secondColon === -1) continue;
|
||||
|
||||
const file = line.slice(0, firstColon);
|
||||
const lineNum = afterFile.slice(0, secondColon);
|
||||
const content = afterFile.slice(secondColon + 1).trim();
|
||||
|
||||
if (file.startsWith('node_modules/') || file.includes('public/cesium')) continue;
|
||||
|
||||
const blameOut = run(`git blame -L ${lineNum},${lineNum} --porcelain "${file}"`);
|
||||
const timeMatch = blameOut.match(/^author-time (\d+)/m);
|
||||
if (!timeMatch) continue;
|
||||
|
||||
const ageInDays = (Date.now() - parseInt(timeMatch[1], 10) * 1000) / 86_400_000;
|
||||
if (ageInDays < STALE_COMMENT_DAYS) continue;
|
||||
|
||||
const issueMatch = content.match(/#(\d+)/);
|
||||
let issueClosed = false;
|
||||
if (issueMatch) {
|
||||
const state = run(`gh issue view ${issueMatch[1]} --json state -q .state 2>/dev/null`);
|
||||
issueClosed = state.toUpperCase() === 'CLOSED';
|
||||
}
|
||||
|
||||
add({
|
||||
type: 'stale-todo',
|
||||
tier: 'A',
|
||||
file,
|
||||
line: parseInt(lineNum, 10),
|
||||
content: content.slice(0, 200),
|
||||
ageInDays: Math.round(ageInDays),
|
||||
issueClosed,
|
||||
linkedIssue: issueMatch ? issueMatch[1] : null,
|
||||
description: issueClosed
|
||||
? `TODO references closed issue #${issueMatch[1]} (${Math.round(ageInDays)}d old) — safe to delete`
|
||||
: `TODO/comment is ${Math.round(ageInDays)} days old — review and resolve or delete`,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// ─── Detector 3: Known anti-patterns ─────────────────────────────────────────
|
||||
const ANTI_PATTERNS = [
|
||||
{
|
||||
id: 'mdc-ref',
|
||||
tier: 'A',
|
||||
globs: ['*.ts', '*.tsx'],
|
||||
pattern: '[\'"].*\\.mdc[\'"]',
|
||||
excludePrefix: 'scripts/',
|
||||
desc: '.mdc file reference — must be .md (project invariant: never .mdc files)',
|
||||
},
|
||||
{
|
||||
id: 'console-log',
|
||||
tier: 'A',
|
||||
globs: ['*.ts', '*.tsx'],
|
||||
pattern: 'console\\.log(',
|
||||
excludePrefix: 'scripts/',
|
||||
desc: 'stray console.log — remove or replace with structured logging',
|
||||
},
|
||||
{
|
||||
id: 'ts-ignore',
|
||||
tier: 'A',
|
||||
globs: ['*.ts', '*.tsx'],
|
||||
pattern: '@ts-ignore',
|
||||
desc: '@ts-ignore suppresses real type errors — remove and fix the underlying type',
|
||||
},
|
||||
{
|
||||
id: 'ts-nocheck',
|
||||
tier: 'A',
|
||||
globs: ['*.ts', '*.tsx'],
|
||||
pattern: '@ts-nocheck',
|
||||
desc: '@ts-nocheck disables all type checking for the file — remove and fix types',
|
||||
},
|
||||
{
|
||||
id: 'hardcoded-url',
|
||||
tier: 'B',
|
||||
globs: ['*.ts', '*.tsx'],
|
||||
pattern: 'localhost:500',
|
||||
excludePrefix: 'scripts/',
|
||||
desc: 'hardcoded engine URL (localhost:5001/5000) — use env var or plugin streamUrl instead',
|
||||
},
|
||||
{
|
||||
id: 'deprecated',
|
||||
tier: 'B',
|
||||
globs: ['*.ts', '*.tsx'],
|
||||
pattern: '@deprecated',
|
||||
desc: '@deprecated JSDoc on a symbol — audit whether all callers have migrated',
|
||||
},
|
||||
];
|
||||
|
||||
function detectAntiPatterns() {
|
||||
for (const { id, tier, globs, pattern, desc, excludePrefix } of ANTI_PATTERNS) {
|
||||
const globArgs = globs.map(g => `"${g}"`).join(' ');
|
||||
const raw = run(`git grep -En "${pattern}" -- ${globArgs}`);
|
||||
if (!raw) continue;
|
||||
|
||||
const hits = raw
|
||||
.split('\n')
|
||||
.filter(l => l && !(excludePrefix && l.startsWith(excludePrefix)))
|
||||
.slice(0, 15);
|
||||
|
||||
for (const line of hits) {
|
||||
const m = line.match(/^([^:]+):(\d+):(.*)/);
|
||||
if (!m) continue;
|
||||
if (m[1].startsWith('node_modules/') || m[1].includes('public/cesium')) continue;
|
||||
add({
|
||||
type: 'anti-pattern',
|
||||
patternId: id,
|
||||
tier,
|
||||
file: m[1],
|
||||
line: parseInt(m[2], 10),
|
||||
content: m[3].trim().slice(0, 200),
|
||||
description: desc,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ─── Detector 4: Oversized source files ──────────────────────────────────────
|
||||
function detectOversizedFiles() {
|
||||
const fileList = run('git ls-files "*.ts" "*.tsx"').split('\n').filter(Boolean);
|
||||
for (const file of fileList) {
|
||||
if (file.startsWith('node_modules/') || file.includes('public/cesium') || file.includes('.next/')) continue;
|
||||
const fullPath = join(ROOT, file);
|
||||
if (!existsSync(fullPath)) continue;
|
||||
const lineCount = readFileSync(fullPath, 'utf8').split('\n').length;
|
||||
if (lineCount > 350) {
|
||||
add({
|
||||
type: 'oversized-file',
|
||||
tier: 'B',
|
||||
file,
|
||||
lines: lineCount,
|
||||
description: `${lineCount} lines exceeds ~300-line convention — extract helpers, split component, or use hooks`,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ─── Detector 5: Orphaned rule file references ───────────────────────────────
|
||||
function detectOrphanedRuleRefs() {
|
||||
const ruleFiles = run('git ls-files ".agents/rules/"').split('\n').filter(f => f.endsWith('.md'));
|
||||
for (const ruleFile of ruleFiles) {
|
||||
const fullPath = join(ROOT, ruleFile);
|
||||
if (!existsSync(fullPath)) continue;
|
||||
const content = readFileSync(fullPath, 'utf8');
|
||||
const seen = new Set();
|
||||
for (const [, ref] of content.matchAll(
|
||||
/`((?:src|packages|local-plugins|local-seeders|\.agents)\/[^`\s]+)`/g
|
||||
)) {
|
||||
const base = ref.replace(/\/\*\*.*/, '').replace(/\/\*.*/, '').replace(/\{[^}]+\}.*/, '');
|
||||
if (!base || seen.has(base)) continue;
|
||||
seen.add(base);
|
||||
const tracked = run(`git ls-files "${base}" "${base}/" 2>/dev/null`);
|
||||
if (!tracked && !existsSync(join(ROOT, base))) {
|
||||
add({
|
||||
type: 'orphaned-rule-ref',
|
||||
tier: 'B',
|
||||
file: ruleFile,
|
||||
ref: base,
|
||||
description: `Rule file references '${base}' which no longer exists — update or remove`,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ─── Detector 6: Orphaned workspace packages ─────────────────────────────────
|
||||
function detectOrphanedPackages() {
|
||||
try {
|
||||
const wsInfo = run('pnpm list --recursive --depth=0 --json 2>/dev/null');
|
||||
if (!wsInfo) return;
|
||||
const pkgs = JSON.parse(wsInfo);
|
||||
const allNames = new Set(pkgs.map(p => p.name).filter(Boolean));
|
||||
const reverseDepCount = Object.fromEntries([...allNames].map(n => [n, 0]));
|
||||
for (const pkg of pkgs) {
|
||||
for (const dep of Object.keys({ ...pkg.dependencies, ...pkg.devDependencies })) {
|
||||
if (reverseDepCount[dep] !== undefined) reverseDepCount[dep]++;
|
||||
}
|
||||
}
|
||||
for (const [name, count] of Object.entries(reverseDepCount)) {
|
||||
const pkg = pkgs.find(p => p.name === name);
|
||||
if (!pkg?.path?.includes('/packages/')) continue;
|
||||
if (count === 0) {
|
||||
add({
|
||||
type: 'orphaned-package',
|
||||
tier: 'B',
|
||||
name,
|
||||
path: relative(ROOT, pkg.path),
|
||||
description: `Workspace package '${name}' has no reverse dependencies inside the monorepo — consider removing`,
|
||||
});
|
||||
}
|
||||
}
|
||||
} catch { /* skip if pnpm unavailable */ }
|
||||
}
|
||||
|
||||
// ─── Detector 7: Old Prisma migrations ───────────────────────────────────────
|
||||
function detectOldMigrations() {
|
||||
const migrationsDir = resolve(ROOT, 'prisma/migrations');
|
||||
if (!existsSync(migrationsDir)) return;
|
||||
const dirs = run(`ls -1 "${migrationsDir}"`).split('\n').filter(Boolean);
|
||||
for (const dir of dirs) {
|
||||
const sqlFile = `prisma/migrations/${dir}/migration.sql`;
|
||||
const lastTouch = run(`git log -1 --format=%ci -- "${sqlFile}"`);
|
||||
if (!lastTouch) continue;
|
||||
const age = daysAgo(lastTouch);
|
||||
if (age < 365) continue;
|
||||
add({
|
||||
type: 'old-migration',
|
||||
tier: 'B',
|
||||
migration: dir,
|
||||
ageDays: Math.floor(age),
|
||||
lastTouched: lastTouch.trim(),
|
||||
description: `Migration '${dir}' is ${Math.floor(age)} days old — verify it is still actively needed`,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// ─── Detector 8: Outdated dependencies ───────────────────────────────────────
|
||||
function detectOutdatedDeps() {
|
||||
if (!existsSync(join(ROOT, 'package.json'))) return;
|
||||
const raw = run('pnpm outdated --no-color 2>/dev/null || true');
|
||||
if (!raw) return;
|
||||
const dataLines = raw
|
||||
.split('\n')
|
||||
.filter(l => l.trim() && !l.startsWith('Package') && !l.startsWith('Legend') && !l.startsWith(' '));
|
||||
for (const line of dataLines.slice(0, 12)) {
|
||||
const cols = line.trim().split(/\s+/);
|
||||
if (cols.length < 3) continue;
|
||||
const [pkg, current, latest] = cols;
|
||||
if (!pkg || !current || !latest || current === latest) continue;
|
||||
const isMajor = current.replace(/^[^0-9]*/, '').split('.')[0] !== latest.replace(/^[^0-9]*/, '').split('.')[0];
|
||||
add({
|
||||
type: 'outdated-dep',
|
||||
tier: 'B',
|
||||
package: pkg,
|
||||
current,
|
||||
latest,
|
||||
isMajor,
|
||||
description: `${pkg}: ${current} → ${latest}${isMajor ? ' ⚠ MAJOR bump — review breaking changes before upgrading' : ''}`,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// ─── Run all detectors ────────────────────────────────────────────────────────
|
||||
console.log('WorldWideView GC Scan');
|
||||
console.log(`Repo: ${run('git remote get-url origin') || ROOT}`);
|
||||
console.log(`Commit: ${run('git rev-parse --short HEAD') || 'unknown'}`);
|
||||
console.log(`Thresholds: branch=${STALE_BRANCH_DAYS}d comment=${STALE_COMMENT_DAYS}d`);
|
||||
console.log('');
|
||||
|
||||
detectStaleBranches();
|
||||
console.log(` stale-branch ${findings.filter(f => f.type === 'stale-branch').length}`);
|
||||
|
||||
detectStaleTodos();
|
||||
console.log(` stale-todo ${findings.filter(f => f.type === 'stale-todo').length}`);
|
||||
|
||||
detectAntiPatterns();
|
||||
console.log(` anti-pattern ${findings.filter(f => f.type === 'anti-pattern').length}`);
|
||||
|
||||
detectOversizedFiles();
|
||||
console.log(` oversized-file ${findings.filter(f => f.type === 'oversized-file').length}`);
|
||||
|
||||
detectOrphanedRuleRefs();
|
||||
console.log(` orphaned-rule-ref ${findings.filter(f => f.type === 'orphaned-rule-ref').length}`);
|
||||
|
||||
detectOrphanedPackages();
|
||||
console.log(` orphaned-package ${findings.filter(f => f.type === 'orphaned-package').length}`);
|
||||
|
||||
detectOldMigrations();
|
||||
console.log(` old-migration ${findings.filter(f => f.type === 'old-migration').length}`);
|
||||
|
||||
detectOutdatedDeps();
|
||||
console.log(` outdated-dep ${findings.filter(f => f.type === 'outdated-dep').length}`);
|
||||
|
||||
// Deduplicate
|
||||
const seen = new Set();
|
||||
const deduped = findings.filter(f => {
|
||||
const key = [
|
||||
f.type,
|
||||
f.file ?? f.package ?? f.name ?? f.migration ?? f.branch ?? '',
|
||||
f.line ?? f.ref ?? '',
|
||||
f.patternId ?? '',
|
||||
].join(':');
|
||||
if (seen.has(key)) return false;
|
||||
seen.add(key);
|
||||
return true;
|
||||
});
|
||||
|
||||
const output = {
|
||||
scanDate: new Date().toISOString(),
|
||||
thresholds: { STALE_BRANCH_DAYS, STALE_COMMENT_DAYS },
|
||||
repo: run('git remote get-url origin') || ROOT,
|
||||
commit: run('git rev-parse --short HEAD') || 'unknown',
|
||||
summary: {
|
||||
total: deduped.length,
|
||||
tierA: deduped.filter(f => f.tier === 'A').length,
|
||||
tierB: deduped.filter(f => f.tier === 'B').length,
|
||||
},
|
||||
findings: deduped,
|
||||
};
|
||||
|
||||
writeFileSync(OUT, JSON.stringify(output, null, 2));
|
||||
console.log('');
|
||||
console.log(`Total: ${deduped.length} (Tier A: ${output.summary.tierA}, Tier B: ${output.summary.tierB})`);
|
||||
console.log(`Output: ${OUT}`);
|
||||
+9
-1
@@ -27,6 +27,7 @@ if (!existsSync(EXAMPLE)) {
|
||||
}
|
||||
|
||||
const secret = randomBytes(32).toString("hex");
|
||||
const encryptionKey = randomBytes(32).toString("hex");
|
||||
let content = readFileSync(EXAMPLE, "utf8");
|
||||
|
||||
// Fill in the AUTH_SECRET line
|
||||
@@ -36,6 +37,13 @@ if (content.includes("AUTH_SECRET=")) {
|
||||
content += `\nAUTH_SECRET=${secret}\n`;
|
||||
}
|
||||
|
||||
// Fill in the ENCRYPTION_MASTER_KEY line
|
||||
if (content.includes("ENCRYPTION_MASTER_KEY=")) {
|
||||
content = content.replace(/^ENCRYPTION_MASTER_KEY=.*$/m, `ENCRYPTION_MASTER_KEY=${encryptionKey}`);
|
||||
} else {
|
||||
content += `\nENCRYPTION_MASTER_KEY=${encryptionKey}\n`;
|
||||
}
|
||||
|
||||
// Strip comment-only sections (keep values)
|
||||
content = content
|
||||
.split("\n")
|
||||
@@ -48,6 +56,6 @@ content = content
|
||||
|
||||
writeFileSync(TARGET, content, "utf8");
|
||||
|
||||
console.log("✅ .env created with a generated AUTH_SECRET.");
|
||||
console.log("✅ .env created with generated AUTH_SECRET and ENCRYPTION_MASTER_KEY.");
|
||||
console.log(" Fill in any optional API keys (Cesium, Bing, OpenSky, etc.)");
|
||||
console.log(" then run: npm run dev");
|
||||
+241
-26
@@ -7,6 +7,7 @@
|
||||
*/
|
||||
|
||||
import fs from "fs";
|
||||
import os from "os";
|
||||
import path from "path";
|
||||
import { build } from "vite";
|
||||
import { fileURLToPath } from "url";
|
||||
@@ -26,9 +27,72 @@ const EXTERNAL_GLOBALS = {
|
||||
"resium": "globalThis.__WWV_HOST__.Resium",
|
||||
};
|
||||
|
||||
/**
|
||||
* Synthetic host-module exports for `@/` imports that plugins use to access
|
||||
* the host application's runtime objects (store, plugin manager, components).
|
||||
*
|
||||
* When a plugin sub-component does `import { useStore } from "@/core/state/store"`,
|
||||
* the tsconfig `@/*` alias (inherited from the main app root tsconfig) would normally
|
||||
* resolve that to the actual `src/core/state/store.ts` file — pulling the entire Zustand
|
||||
* store (and its transitive deps like `src/core/edition.ts`) into the bundle.
|
||||
* This plugin intercepts those imports at the resolveId stage, before Vite touches
|
||||
* the filesystem, and substitutes a synthetic module that reads from the host globals
|
||||
* injected at runtime by `hostGlobals.ts`.
|
||||
*/
|
||||
const HOST_MODULE_SYNTHETICS = {
|
||||
"@/core/state/store": `export const useStore = globalThis.__WWV_HOST__.useStore;`,
|
||||
"@/core/plugins/PluginManager": `export const pluginManager = globalThis.__WWV_HOST__.pluginManager;`,
|
||||
"@/components/video/CameraStream": `export const CameraStream = globalThis.__WWV_HOST__.CameraStream;`,
|
||||
"zustand": `
|
||||
const zustand = globalThis.__WWV_HOST__.zustand || {};
|
||||
export default zustand;
|
||||
export const { create, createStore } = zustand;
|
||||
`,
|
||||
};
|
||||
|
||||
/**
|
||||
* @function wwvHostRedirectPlugin
|
||||
* @description Vite plugin that intercepts host-app module imports (`@/core/...`,
|
||||
* `@/components/...`) in local plugin builds and redirects them to the runtime
|
||||
* host globals instead of bundling the full app source tree.
|
||||
*
|
||||
* @returns {import('vite').Plugin}
|
||||
*/
|
||||
function wwvHostRedirectPlugin() {
|
||||
return {
|
||||
name: "wwv-host-redirect",
|
||||
enforce: "pre",
|
||||
resolveId(id) {
|
||||
if (id in HOST_MODULE_SYNTHETICS) return `\0${id}`;
|
||||
return null;
|
||||
},
|
||||
load(id) {
|
||||
if (!id.startsWith("\0")) return null;
|
||||
const originalId = id.slice(1);
|
||||
return HOST_MODULE_SYNTHETICS[originalId] ?? null;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @function readJsonFile
|
||||
* @description Reads a UTF-8 JSON file, tolerating a leading BOM (U+FEFF).
|
||||
* Node's `fs.readFileSync(p, 'utf-8')` preserves the BOM byte, which `JSON.parse`
|
||||
* then rejects with "Unexpected token". Scaffolders and editors on Windows
|
||||
* occasionally emit BOMs into `package.json`; pnpm/npm strip them silently,
|
||||
* so we match that behavior here to avoid breaking dev on otherwise-valid files.
|
||||
* @param {string} filePath
|
||||
* @returns {any}
|
||||
*/
|
||||
function readJsonFile(filePath) {
|
||||
let text = fs.readFileSync(filePath, "utf-8");
|
||||
if (text.charCodeAt(0) === 0xFEFF) text = text.slice(1);
|
||||
return JSON.parse(text);
|
||||
}
|
||||
|
||||
/**
|
||||
* @function discoverLocalPlugins
|
||||
* @description Finds all directories in `local-plugins/` that contain a valid
|
||||
* @description Finds all directories in `local-plugins/` that contain a valid
|
||||
* `package.json` with a `worldwideview` manifest block.
|
||||
* @returns {Array<{dir: string, manifest: any, pluginDir: string}>}
|
||||
*/
|
||||
@@ -40,43 +104,141 @@ export function discoverLocalPlugins() {
|
||||
if (dir.startsWith(".")) return false;
|
||||
const pkgPath = path.join(LOCAL_PLUGINS_DIR, dir, "package.json");
|
||||
if (!fs.existsSync(pkgPath)) return false;
|
||||
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
|
||||
const pkg = readJsonFile(pkgPath);
|
||||
return !!pkg.worldwideview;
|
||||
})
|
||||
.map(dir => {
|
||||
const pkgPath = path.join(LOCAL_PLUGINS_DIR, dir, "package.json");
|
||||
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
|
||||
const pkg = readJsonFile(pkgPath);
|
||||
const manifest = pkg.worldwideview;
|
||||
manifest.version = pkg.version;
|
||||
manifest.name = pkg.name;
|
||||
manifest.description = pkg.description;
|
||||
return { dir, manifest, pluginDir: path.join(LOCAL_PLUGINS_DIR, dir) };
|
||||
return { dir, manifest, pkg, pluginDir: path.join(LOCAL_PLUGINS_DIR, dir) };
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @function buildPlugin
|
||||
* @description Invokes the Vite build engine to compile a plugin's source
|
||||
* into a single ES module, externalizing shared host dependencies.
|
||||
* @function resolvePluginEntry
|
||||
* @description Resolves the TypeScript source entry file for a plugin.
|
||||
*
|
||||
* Resolution order:
|
||||
* 1. `worldwideview.dev_entry` — explicit override in the manifest block
|
||||
* 2. `pkg.types` — if it points to a .ts/.tsx source file (not a .d.ts declaration)
|
||||
* 3. `pkg.source` — explicit source field (less common, but valid)
|
||||
* 4. Heuristic fallback: src/index.ts → src/index.tsx → index.ts → index.tsx
|
||||
*
|
||||
* @param {string} pluginDir - Absolute path to the plugin directory.
|
||||
* @param {any} manifest - The parsed `worldwideview` manifest block.
|
||||
* @param {any} pkg - The full parsed package.json object.
|
||||
* @returns {string|null} Absolute path to the entry file, or null if not found.
|
||||
*/
|
||||
export async function buildPlugin({ dir, manifest, pluginDir }) {
|
||||
const devEntry = manifest.dev_entry || "index.ts";
|
||||
let entryFile = path.join(pluginDir, devEntry);
|
||||
function resolvePluginEntry(pluginDir, manifest, pkg) {
|
||||
const candidates = [];
|
||||
|
||||
// Fallback: check for .tsx
|
||||
if (!fs.existsSync(entryFile)) {
|
||||
const tsxEntry = devEntry.replace(".ts", ".tsx");
|
||||
entryFile = path.join(pluginDir, tsxEntry);
|
||||
if (!fs.existsSync(entryFile)) {
|
||||
console.warn(`[sync] ⚠ No entry file found for ${dir}, skipping`);
|
||||
return false;
|
||||
if (manifest.dev_entry) {
|
||||
candidates.push(path.join(pluginDir, manifest.dev_entry));
|
||||
}
|
||||
|
||||
// pkg.types points to the TS source in all WWV plugins (e.g. "src/index.ts")
|
||||
if (pkg.types && !pkg.types.endsWith(".d.ts")) {
|
||||
candidates.push(path.join(pluginDir, pkg.types));
|
||||
}
|
||||
|
||||
if (pkg.source) {
|
||||
candidates.push(path.join(pluginDir, pkg.source));
|
||||
}
|
||||
|
||||
// Heuristic fallbacks
|
||||
for (const rel of ["src/index.ts", "src/index.tsx", "index.ts", "index.tsx"]) {
|
||||
candidates.push(path.join(pluginDir, rel));
|
||||
}
|
||||
|
||||
return candidates.find(f => fs.existsSync(f)) ?? null;
|
||||
}
|
||||
|
||||
const SKIP_DIRS = new Set(["dist", "node_modules", ".git", ".turbo", ".vite"]);
|
||||
|
||||
/**
|
||||
* @function latestSourceMtime
|
||||
* @description Walks a plugin directory and returns the newest mtime (ms) across
|
||||
* source files. Used to decide whether a cached `dist/frontend.mjs` is still valid.
|
||||
* Skips build/output dirs so this is fast even on cold disks.
|
||||
* @param {string} rootDir
|
||||
* @returns {number} newest mtime in ms, or 0 if no files found
|
||||
*/
|
||||
function latestSourceMtime(rootDir) {
|
||||
let newest = 0;
|
||||
/** @param {string} dir */
|
||||
function walk(dir) {
|
||||
let entries;
|
||||
try {
|
||||
entries = fs.readdirSync(dir, { withFileTypes: true });
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
for (const entry of entries) {
|
||||
if (entry.name.startsWith(".") && entry.name !== ".env") continue;
|
||||
if (SKIP_DIRS.has(entry.name)) continue;
|
||||
const full = path.join(dir, entry.name);
|
||||
if (entry.isDirectory()) {
|
||||
walk(full);
|
||||
} else if (entry.isFile()) {
|
||||
const m = fs.statSync(full).mtimeMs;
|
||||
if (m > newest) newest = m;
|
||||
}
|
||||
}
|
||||
}
|
||||
walk(rootDir);
|
||||
return newest;
|
||||
}
|
||||
|
||||
/**
|
||||
* @function isBuildFresh
|
||||
* @description Returns true if the plugin's existing `dist/frontend.mjs` is newer
|
||||
* than every source file under its directory — meaning Vite would produce a
|
||||
* byte-identical bundle and the build can be skipped.
|
||||
* @param {string} pluginDir
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function isBuildFresh(pluginDir) {
|
||||
const distFile = path.join(pluginDir, "dist", "frontend.mjs");
|
||||
if (!fs.existsSync(distFile)) return false;
|
||||
const distMtime = fs.statSync(distFile).mtimeMs;
|
||||
const sourceMtime = latestSourceMtime(pluginDir);
|
||||
return distMtime >= sourceMtime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @function buildPlugin
|
||||
* @description Invokes the Vite build engine to compile a plugin's source
|
||||
* into a single ES module, externalizing shared host dependencies.
|
||||
*
|
||||
* Returns `"fresh"` if an up-to-date `dist/frontend.mjs` already exists (no build run),
|
||||
* `true` if Vite produced a new bundle, or `false` on failure.
|
||||
*/
|
||||
export async function buildPlugin({ dir, manifest, pkg, pluginDir }) {
|
||||
if (isBuildFresh(pluginDir)) {
|
||||
return "fresh";
|
||||
}
|
||||
|
||||
const entryFile = resolvePluginEntry(pluginDir, manifest, pkg ?? {});
|
||||
|
||||
if (!entryFile) {
|
||||
console.warn(`[sync] ⚠ No entry file found for ${dir}, skipping`);
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
await build({
|
||||
root: pluginDir,
|
||||
// Disable auto-loading the plugin's own vite.config.ts — the local
|
||||
// plugins' node_modules may be symlinked to a different repo's SDK
|
||||
// build (worktree scenario), which breaks config loading. The sync
|
||||
// script provides all necessary config inline.
|
||||
configFile: false,
|
||||
logLevel: "warn",
|
||||
plugins: [wwvHostRedirectPlugin()],
|
||||
build: {
|
||||
lib: {
|
||||
entry: entryFile,
|
||||
@@ -89,10 +251,22 @@ export async function buildPlugin({ dir, manifest, pluginDir }) {
|
||||
external: Object.keys(EXTERNAL_GLOBALS),
|
||||
output: {
|
||||
globals: EXTERNAL_GLOBALS,
|
||||
codeSplitting: false,
|
||||
inlineDynamicImports: true,
|
||||
banner: '"use client";',
|
||||
},
|
||||
plugins: [(await import("rollup-plugin-external-globals")).default(EXTERNAL_GLOBALS)],
|
||||
plugins: [
|
||||
{
|
||||
name: 'replace-process-env',
|
||||
transform(code) {
|
||||
if (!code.includes('process.env.NODE_ENV')) return null;
|
||||
return {
|
||||
code: code.replace(/process\.env\.NODE_ENV/g, '"production"'),
|
||||
map: null,
|
||||
};
|
||||
},
|
||||
},
|
||||
(await import("rollup-plugin-external-globals")).default(EXTERNAL_GLOBALS),
|
||||
],
|
||||
onwarn(warning, warn) {
|
||||
if (warning.code === 'MODULE_LEVEL_DIRECTIVE' && warning.message.includes('"use client"')) {
|
||||
return;
|
||||
@@ -114,7 +288,7 @@ export async function buildPlugin({ dir, manifest, pluginDir }) {
|
||||
}
|
||||
}
|
||||
|
||||
export function syncToPublic({ dir, manifest, pluginDir }) {
|
||||
export function syncToPublic({ dir, manifest, pluginDir }, { quiet = false } = {}) {
|
||||
const publicName = manifest.id || dir.replace("wwv-plugin-", "");
|
||||
const targetDir = path.join(OUTPUT_DIR, publicName);
|
||||
const distFile = path.join(pluginDir, "dist", "frontend.mjs");
|
||||
@@ -130,6 +304,13 @@ export function syncToPublic({ dir, manifest, pluginDir }) {
|
||||
if (fs.existsSync(distMap)) {
|
||||
fs.copyFileSync(distMap, path.join(targetDir, "frontend.mjs.map"));
|
||||
}
|
||||
// Copy any CSS files emitted alongside the bundle (e.g. from gridstack imports)
|
||||
const distDir = path.join(pluginDir, "dist");
|
||||
for (const f of fs.readdirSync(distDir)) {
|
||||
if (f.endsWith(".css")) {
|
||||
fs.copyFileSync(path.join(distDir, f), path.join(targetDir, f));
|
||||
}
|
||||
}
|
||||
|
||||
// Generate plugin.json manifest for the marketplace load route
|
||||
const pluginJson = {
|
||||
@@ -151,7 +332,7 @@ export function syncToPublic({ dir, manifest, pluginDir }) {
|
||||
JSON.stringify(pluginJson, null, 2)
|
||||
);
|
||||
|
||||
console.log(`[sync] ✅ ${publicName} → public/plugins-local/${publicName}/`);
|
||||
if (!quiet) console.log(`[sync] ✅ ${publicName} → public/plugins-local/${publicName}/`);
|
||||
}
|
||||
|
||||
// Clean stale plugins from public/plugins-local/ that no longer exist in local-plugins/
|
||||
@@ -166,6 +347,32 @@ function cleanStale(activeIds) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @function runWithConcurrency
|
||||
* @description Runs an async worker over `items` with a fixed concurrency cap.
|
||||
* Vite builds are CPU-bound; running all ~30 in parallel thrashes the scheduler
|
||||
* and balloons RSS. A cap around half the logical cores keeps wall-clock low
|
||||
* without starving the rest of the dev environment (Next.js, the data engine).
|
||||
* @template T, R
|
||||
* @param {T[]} items
|
||||
* @param {number} concurrency
|
||||
* @param {(item: T) => Promise<R>} worker
|
||||
* @returns {Promise<R[]>}
|
||||
*/
|
||||
async function runWithConcurrency(items, concurrency, worker) {
|
||||
const results = new Array(items.length);
|
||||
let cursor = 0;
|
||||
const workers = Array.from({ length: Math.min(concurrency, items.length) }, async () => {
|
||||
while (true) {
|
||||
const i = cursor++;
|
||||
if (i >= items.length) return;
|
||||
results[i] = await worker(items[i]);
|
||||
}
|
||||
});
|
||||
await Promise.all(workers);
|
||||
return results;
|
||||
}
|
||||
|
||||
export async function syncAll() {
|
||||
const plugins = discoverLocalPlugins();
|
||||
|
||||
@@ -175,12 +382,20 @@ export async function syncAll() {
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(`[sync] Found ${plugins.length} local plugin(s): ${plugins.map(p => p.dir).join(", ")}`);
|
||||
const concurrency = Math.max(2, Math.min(plugins.length, Math.ceil(os.cpus().length / 2)));
|
||||
console.log(`[sync] Found ${plugins.length} local plugin(s); building with concurrency=${concurrency}`);
|
||||
const started = Date.now();
|
||||
|
||||
for (const plugin of plugins) {
|
||||
const ok = await buildPlugin(plugin);
|
||||
if (ok) syncToPublic(plugin);
|
||||
}
|
||||
let freshCount = 0;
|
||||
let builtCount = 0;
|
||||
await runWithConcurrency(plugins, concurrency, async (plugin) => {
|
||||
const result = await buildPlugin(plugin);
|
||||
if (result === "fresh") freshCount++;
|
||||
else if (result) builtCount++;
|
||||
if (result) syncToPublic(plugin, { quiet: result === "fresh" });
|
||||
});
|
||||
|
||||
console.log(`[sync] Done in ${((Date.now() - started) / 1000).toFixed(1)}s (${builtCount} built, ${freshCount} cached)`);
|
||||
|
||||
const activeIds = plugins.map(p => p.manifest.id || p.dir.replace("wwv-plugin-", ""));
|
||||
cleanStale(activeIds);
|
||||
|
||||
@@ -15,40 +15,66 @@ if (!fs.existsSync(LOCAL_PLUGINS_DIR)) {
|
||||
let debounceTimeout = null;
|
||||
let isSyncing = false;
|
||||
let pendingSync = false;
|
||||
/** Files changed since last sync completed — collected during the debounce window */
|
||||
const pendingChanges = new Set();
|
||||
|
||||
function handleFileChange(eventType, filename) {
|
||||
if (filename && (
|
||||
filename.includes("dist") ||
|
||||
filename.includes("node_modules") ||
|
||||
if (!filename) return;
|
||||
if (
|
||||
filename.includes("dist") ||
|
||||
filename.includes("node_modules") ||
|
||||
filename.endsWith(".map") ||
|
||||
filename.includes(".git")
|
||||
)) return; // ignore build artifacts and git internals
|
||||
|
||||
) return; // ignore build artifacts and git internals
|
||||
|
||||
pendingChanges.add(filename);
|
||||
|
||||
if (debounceTimeout) {
|
||||
clearTimeout(debounceTimeout);
|
||||
}
|
||||
|
||||
|
||||
debounceTimeout = setTimeout(async () => {
|
||||
if (isSyncing) {
|
||||
pendingSync = true;
|
||||
return;
|
||||
}
|
||||
await runSync(filename);
|
||||
await runSync();
|
||||
}, 500);
|
||||
}
|
||||
|
||||
async function runSync(filename) {
|
||||
/**
|
||||
* Pulls plugin slugs out of changed file paths so we can name what triggered the rebuild.
|
||||
* fs.watch on `local-plugins/` emits paths like `aviation/src/index.ts` (POSIX or Windows).
|
||||
*/
|
||||
function summarizeChangedPlugins(files) {
|
||||
const slugs = new Set();
|
||||
for (const f of files) {
|
||||
const head = f.split(/[\\/]/)[0];
|
||||
if (head) slugs.add(head);
|
||||
}
|
||||
return [...slugs];
|
||||
}
|
||||
|
||||
async function runSync() {
|
||||
isSyncing = true;
|
||||
console.log(`\n[watch] Change detected in local plugins (file: ${filename}). Syncing...`);
|
||||
const changed = summarizeChangedPlugins(pendingChanges);
|
||||
pendingChanges.clear();
|
||||
const label = changed.length === 0
|
||||
? "pending changes"
|
||||
: changed.length <= 3
|
||||
? changed.join(", ")
|
||||
: `${changed.slice(0, 3).join(", ")} (+${changed.length - 3} more)`;
|
||||
console.log(`\n[watch] 🔄 Change detected in: ${label}`);
|
||||
try {
|
||||
await syncAll();
|
||||
console.log(`[watch] ✨ Hot-reload ready`);
|
||||
} catch (err) {
|
||||
console.error(`[watch] Sync failed:`, err);
|
||||
} finally {
|
||||
isSyncing = false;
|
||||
if (pendingSync) {
|
||||
pendingSync = false;
|
||||
await runSync("pending changes");
|
||||
await runSync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
import { describe, it, expect, vi, beforeEach } from "vitest";
|
||||
import { NextRequest } from "next/server";
|
||||
import { auth } from "@/lib/auth";
|
||||
import { getTicket } from "@/lib/auth/ticketClient";
|
||||
import { GET } from "./route";
|
||||
|
||||
vi.mock("@/lib/auth", () => ({ auth: vi.fn() }));
|
||||
vi.mock("@/lib/auth/ticketClient", () => ({ getTicket: vi.fn() }));
|
||||
vi.mock("@/core/edition", () => ({ isAuthEnabled: true }));
|
||||
|
||||
describe("GET /api/auth/ticket", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
it("returns 401 when no session exists", async () => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
vi.mocked(auth).mockResolvedValue(null as any);
|
||||
const req = new NextRequest("http://localhost/api/auth/ticket?pluginId=aviation");
|
||||
const res = await GET(req);
|
||||
expect(res.status).toBe(401);
|
||||
expect(await res.json()).toEqual({ error: "Unauthorized" });
|
||||
});
|
||||
|
||||
it("returns 400 when pluginId query param is missing", async () => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
vi.mocked(auth).mockResolvedValue({ user: { id: "u1" } } as any);
|
||||
const req = new NextRequest("http://localhost/api/auth/ticket");
|
||||
const res = await GET(req);
|
||||
expect(res.status).toBe(400);
|
||||
expect(await res.json()).toEqual({ error: "Missing pluginId" });
|
||||
});
|
||||
|
||||
it("returns 500 when getTicket throws", async () => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
vi.mocked(auth).mockResolvedValue({ user: { id: "u1" } } as any);
|
||||
vi.mocked(getTicket).mockRejectedValue(new Error("Marketplace unreachable"));
|
||||
const req = new NextRequest("http://localhost/api/auth/ticket?pluginId=aviation");
|
||||
const res = await GET(req);
|
||||
expect(res.status).toBe(500);
|
||||
expect(await res.json()).toEqual({ error: "Failed to obtain plugin ticket" });
|
||||
});
|
||||
|
||||
it("returns 200 with token on success", async () => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
vi.mocked(auth).mockResolvedValue({ user: { id: "u1" } } as any);
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
vi.mocked(getTicket).mockResolvedValue("plugin-ticket-abc" as any);
|
||||
const req = new NextRequest("http://localhost/api/auth/ticket?pluginId=aviation");
|
||||
const res = await GET(req);
|
||||
expect(res.status).toBe(200);
|
||||
expect(await res.json()).toEqual({ token: "plugin-ticket-abc" });
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,32 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { auth } from "@/lib/auth";
|
||||
import { isAuthEnabled } from "@/core/edition";
|
||||
import { getTicket } from "@/lib/auth/ticketClient";
|
||||
|
||||
/**
|
||||
* GET /api/auth/ticket?pluginId=<id>
|
||||
* Returns a short-lived PluginTicket for the given plugin.
|
||||
* Used by WsClient (browser) to obtain auth tokens without DB access.
|
||||
*/
|
||||
export async function GET(req: NextRequest) {
|
||||
if (isAuthEnabled) {
|
||||
const session = await auth();
|
||||
if (!session?.user) {
|
||||
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
||||
}
|
||||
}
|
||||
|
||||
const pluginId = req.nextUrl.searchParams.get("pluginId");
|
||||
if (!pluginId) {
|
||||
return NextResponse.json({ error: "Missing pluginId" }, { status: 400 });
|
||||
}
|
||||
|
||||
try {
|
||||
const token = await getTicket(pluginId);
|
||||
return NextResponse.json({ token });
|
||||
} catch (err) {
|
||||
const message = err instanceof Error ? err.message : String(err);
|
||||
console.error("[ticket-route]", message);
|
||||
return NextResponse.json({ error: "Failed to obtain plugin ticket" }, { status: 500 });
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ import { auth } from "@/lib/auth";
|
||||
import { isAuthEnabled } from "@/core/edition";
|
||||
import { cameraProxyLimiter } from "@/lib/rateLimiters";
|
||||
import { getClientIp } from "@/lib/rateLimit";
|
||||
import { safeFetch } from "@/lib/security/ssrf";
|
||||
|
||||
const MAX_IFRAME_DURATION_MS = 10 * 1000; // 10 seconds timeout for HTML
|
||||
|
||||
@@ -28,13 +29,14 @@ export async function GET(req: NextRequest) {
|
||||
}
|
||||
|
||||
try {
|
||||
const upstream = await fetch(targetUrl, {
|
||||
const upstream = await safeFetch(targetUrl, {
|
||||
headers: {
|
||||
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
|
||||
Accept: "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8",
|
||||
"Accept-Language": "en-US,en;q=0.5",
|
||||
},
|
||||
signal: AbortSignal.timeout(MAX_IFRAME_DURATION_MS),
|
||||
maxSize: 5 * 1024 * 1024,
|
||||
timeout: MAX_IFRAME_DURATION_MS,
|
||||
});
|
||||
|
||||
if (!upstream.ok) {
|
||||
@@ -53,7 +55,6 @@ export async function GET(req: NextRequest) {
|
||||
headers: {
|
||||
"Content-Type": contentType,
|
||||
"Cache-Control": "no-store",
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -76,8 +77,6 @@ export async function GET(req: NextRequest) {
|
||||
"Content-Type": contentType,
|
||||
"Cache-Control": "no-store",
|
||||
"X-Content-Type-Options": "nosniff",
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
"Access-Control-Allow-Methods": "GET, OPTIONS",
|
||||
},
|
||||
});
|
||||
} catch (error: unknown) {
|
||||
@@ -89,15 +88,3 @@ export async function GET(req: NextRequest) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export async function OPTIONS() {
|
||||
return new Response(null, {
|
||||
status: 204,
|
||||
headers: {
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
"Access-Control-Allow-Methods": "GET, OPTIONS",
|
||||
"Access-Control-Allow-Headers": "Content-Type",
|
||||
"Access-Control-Max-Age": "86400",
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -31,7 +31,7 @@ export async function GET(req: NextRequest) {
|
||||
const upstream = await safeFetch(targetUrl, {
|
||||
headers: { "User-Agent": "WorldWideView/1.0" },
|
||||
timeout: MAX_STREAM_DURATION_MS,
|
||||
maxSize: 100 * 1024 * 1024, // 100MB for streams
|
||||
streaming: true,
|
||||
});
|
||||
|
||||
if (!upstream.ok) {
|
||||
|
||||
@@ -47,18 +47,19 @@ export async function GET(req: NextRequest) {
|
||||
headers: { "User-Agent": "WorldWideView/1.0" },
|
||||
signal: AbortSignal.timeout(TIMEOUT_MS)
|
||||
});
|
||||
} catch (headError: any) {
|
||||
} catch (headError: unknown) {
|
||||
const err = headError as Error & { cause?: { code?: string } };
|
||||
// Primitive IP camera servers (like Insecam sources) often aggressively drop the TCP connection
|
||||
// instead of returning 405 when they see an unsupported HTTP method like HEAD.
|
||||
// If the socket was closed unexpectedly, retry with GET.
|
||||
if (headError.cause?.code === 'UND_ERR_SOCKET' || headError.message?.includes('fetch failed')) {
|
||||
if (err.cause?.code === 'UND_ERR_SOCKET' || err.message?.includes('fetch failed')) {
|
||||
response = await fetch(url, {
|
||||
method: "GET",
|
||||
headers: { "User-Agent": "WorldWideView/1.0" },
|
||||
signal: AbortSignal.timeout(TIMEOUT_MS)
|
||||
});
|
||||
} else {
|
||||
throw headError;
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,13 +82,14 @@ export async function GET(req: NextRequest) {
|
||||
contentType: response.headers.get("content-type"),
|
||||
latencyMs: Date.now() - startTime
|
||||
});
|
||||
} catch (error: any) {
|
||||
const realError = error.cause || error;
|
||||
const code = realError?.code || error?.code || realError?.name || error?.name;
|
||||
} catch (error: unknown) {
|
||||
const err = error as Error & { cause?: { code?: string, message?: string, name?: string }, code?: string };
|
||||
const realError = err.cause || err;
|
||||
const code = realError?.code || err?.code || realError?.name || err?.name;
|
||||
|
||||
let displayError = error?.message || "Unknown error";
|
||||
let displayError = err?.message || "Unknown error";
|
||||
if (code && code !== 'TypeError' && code !== 'Error') {
|
||||
displayError = `[${code}] ${realError?.message || error?.message || ""}`;
|
||||
displayError = `[${code}] ${realError?.message || err?.message || ""}`;
|
||||
}
|
||||
|
||||
// Make sure we don't accidentally categorize a malformed HTTP response as a timeout
|
||||
@@ -95,7 +97,7 @@ export async function GET(req: NextRequest) {
|
||||
return NextResponse.json({ status: "error", error: displayError, latencyMs: Date.now() - startTime });
|
||||
}
|
||||
|
||||
if (error?.name === "TimeoutError" || displayError.includes("timeout") || code === "UND_ERR_CONNECT_TIMEOUT") {
|
||||
if (err?.name === "TimeoutError" || displayError.includes("timeout") || code === "UND_ERR_CONNECT_TIMEOUT") {
|
||||
return NextResponse.json({ status: "timeout", error: "Connection timed out", latencyMs: Date.now() - startTime });
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
export const revalidate = 60;
|
||||
|
||||
const WTIA_POSITIONS_URL = "https://api.wheretheiss.at/v1/satellites/25544/positions";
|
||||
const MAX_TIMESTAMPS = 10;
|
||||
|
||||
function isValidPosition(item: any): boolean {
|
||||
return (
|
||||
item != null
|
||||
&& typeof item === "object"
|
||||
&& Number.isFinite(item.latitude)
|
||||
&& Number.isFinite(item.longitude)
|
||||
&& Number.isFinite(item.altitude)
|
||||
&& Number.isFinite(item.velocity)
|
||||
&& Number.isFinite(item.timestamp)
|
||||
);
|
||||
}
|
||||
|
||||
export async function GET(request: Request) {
|
||||
const { searchParams } = new URL(request.url);
|
||||
const timestampsParam = searchParams.get("timestamps");
|
||||
|
||||
if (!timestampsParam) {
|
||||
return NextResponse.json(
|
||||
{ error: "Missing required 'timestamps' query parameter" },
|
||||
{ status: 400 },
|
||||
);
|
||||
}
|
||||
|
||||
const timestamps = timestampsParam
|
||||
.split(",")
|
||||
.map((t) => t.trim())
|
||||
.filter((t) => /^\d+$/.test(t));
|
||||
|
||||
if (timestamps.length === 0) {
|
||||
return NextResponse.json(
|
||||
{ error: "No valid timestamps provided" },
|
||||
{ status: 400 },
|
||||
);
|
||||
}
|
||||
|
||||
if (timestamps.length > MAX_TIMESTAMPS) {
|
||||
return NextResponse.json(
|
||||
{ error: `Maximum ${MAX_TIMESTAMPS} timestamps allowed per request` },
|
||||
{ status: 400 },
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
const url = `${WTIA_POSITIONS_URL}?timestamps=${timestamps.join(",")}&units=kilometers`;
|
||||
|
||||
const response = await fetch(url, {
|
||||
headers: {
|
||||
Accept: "application/json",
|
||||
"User-Agent": "WorldWideView/1.0",
|
||||
},
|
||||
next: { revalidate },
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
return NextResponse.json(
|
||||
{ error: "Failed to fetch ISS positions" },
|
||||
{ status: 502 },
|
||||
);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
const positions = (Array.isArray(data) ? data : [])
|
||||
.filter(isValidPosition)
|
||||
.map((p) => ({
|
||||
latitude: p.latitude,
|
||||
longitude: p.longitude,
|
||||
altitude: p.altitude,
|
||||
velocity: p.velocity,
|
||||
visibility: p.visibility,
|
||||
timestamp: p.timestamp,
|
||||
}));
|
||||
|
||||
return NextResponse.json({ positions });
|
||||
} catch (error) {
|
||||
console.error("[IssPositionsRoute] Error:", error);
|
||||
return NextResponse.json(
|
||||
{ error: "Failed to fetch ISS positions" },
|
||||
{ status: 502 },
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
export const revalidate = 10;
|
||||
|
||||
const WTIA_URL = "https://api.wheretheiss.at/v1/satellites/25544";
|
||||
|
||||
function isValidResponse(data: any): boolean {
|
||||
return (
|
||||
data != null
|
||||
&& typeof data === "object"
|
||||
&& Number.isFinite(data.latitude)
|
||||
&& Number.isFinite(data.longitude)
|
||||
&& Number.isFinite(data.altitude)
|
||||
&& Number.isFinite(data.velocity)
|
||||
&& Number.isFinite(data.timestamp)
|
||||
);
|
||||
}
|
||||
|
||||
export async function GET() {
|
||||
try {
|
||||
const response = await fetch(WTIA_URL, {
|
||||
headers: {
|
||||
Accept: "application/json",
|
||||
"User-Agent": "WorldWideView/1.0",
|
||||
},
|
||||
next: { revalidate },
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
return NextResponse.json(
|
||||
{ error: "Failed to fetch ISS position" },
|
||||
{ status: 502 },
|
||||
);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
if (!isValidResponse(data)) {
|
||||
return NextResponse.json(
|
||||
{ error: "Invalid ISS position data" },
|
||||
{ status: 502 },
|
||||
);
|
||||
}
|
||||
|
||||
return NextResponse.json({
|
||||
id: data.id,
|
||||
name: data.name,
|
||||
latitude: data.latitude,
|
||||
longitude: data.longitude,
|
||||
altitude: data.altitude,
|
||||
velocity: data.velocity,
|
||||
visibility: data.visibility,
|
||||
footprint: data.footprint,
|
||||
timestamp: data.timestamp,
|
||||
units: data.units,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("[IssRoute] Error:", error);
|
||||
return NextResponse.json(
|
||||
{ error: "Failed to fetch ISS position" },
|
||||
{ status: 502 },
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
export const revalidate = 3600;
|
||||
|
||||
const WTIA_TLE_URL = "https://api.wheretheiss.at/v1/satellites/25544/tles/latest";
|
||||
|
||||
function isValidTle(data: any): boolean {
|
||||
return (
|
||||
data != null
|
||||
&& typeof data === "object"
|
||||
&& typeof data.line1 === "string"
|
||||
&& typeof data.line2 === "string"
|
||||
&& data.line1.length > 0
|
||||
&& data.line2.length > 0
|
||||
&& Number.isFinite(data.tle_timestamp)
|
||||
);
|
||||
}
|
||||
|
||||
export async function GET() {
|
||||
try {
|
||||
const response = await fetch(WTIA_TLE_URL, {
|
||||
headers: {
|
||||
Accept: "application/json",
|
||||
"User-Agent": "WorldWideView/1.0",
|
||||
},
|
||||
next: { revalidate },
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
return NextResponse.json(
|
||||
{ error: "Failed to fetch ISS TLE data" },
|
||||
{ status: 502 },
|
||||
);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
if (!isValidTle(data)) {
|
||||
return NextResponse.json(
|
||||
{ error: "Invalid ISS TLE data" },
|
||||
{ status: 502 },
|
||||
);
|
||||
}
|
||||
|
||||
return NextResponse.json({
|
||||
id: data.id,
|
||||
name: data.name,
|
||||
header: data.header,
|
||||
line1: data.line1,
|
||||
line2: data.line2,
|
||||
tleTimestamp: data.tle_timestamp,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("[IssTleRoute] Error:", error);
|
||||
return NextResponse.json(
|
||||
{ error: "Failed to fetch ISS TLE data" },
|
||||
{ status: 502 },
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -21,16 +21,18 @@ export async function GET(req: NextRequest) {
|
||||
|
||||
const marketplaceUrl = process.env.NEXT_PUBLIC_WWV_MARKETPLACE_URL || "https://app.worldwideview.dev";
|
||||
const issuer = new URL(marketplaceUrl);
|
||||
const server = {
|
||||
issuer: issuer.toString(),
|
||||
authorization_endpoint: new URL("/oauth/authorize", issuer).toString(),
|
||||
token_endpoint: new URL("/api/tickets/exchange", issuer).toString(),
|
||||
};
|
||||
const config = { server, clientId: "local-app" };
|
||||
|
||||
const config = new client.Configuration(
|
||||
{
|
||||
issuer: issuer.toString(),
|
||||
authorization_endpoint: new URL("/oauth/authorize", issuer).toString(),
|
||||
token_endpoint: new URL("/api/oauth/token", issuer).toString(),
|
||||
},
|
||||
"local-app",
|
||||
);
|
||||
|
||||
try {
|
||||
const tokens = await client.authorizationCodeGrant(
|
||||
config as any,
|
||||
config,
|
||||
new URL(req.url),
|
||||
{ expectedState: stateCookie, pkceCodeVerifier: verifierCookie }
|
||||
);
|
||||
@@ -54,8 +56,8 @@ export async function GET(req: NextRequest) {
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch (err: any) {
|
||||
console.error("[PKCE] Exchange failed:", err.message);
|
||||
} catch (err) {
|
||||
console.error("[PKCE] Exchange failed:", err instanceof Error ? err.message : String(err));
|
||||
return NextResponse.json({ error: "Failed to exchange authorization code" }, { status: 500 });
|
||||
}
|
||||
|
||||
@@ -65,7 +67,7 @@ export async function GET(req: NextRequest) {
|
||||
httpOnly: true,
|
||||
secure: isHttps,
|
||||
sameSite: "lax",
|
||||
path: "/api/marketplace/callback",
|
||||
path: "/", // must match the path used at Set-Cookie time
|
||||
maxAge: 0
|
||||
});
|
||||
|
||||
@@ -73,7 +75,7 @@ export async function GET(req: NextRequest) {
|
||||
httpOnly: true,
|
||||
secure: isHttps,
|
||||
sameSite: "lax",
|
||||
path: "/api/marketplace/callback",
|
||||
path: "/", // must match the path used at Set-Cookie time
|
||||
maxAge: 0
|
||||
});
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ export async function GET(req: NextRequest) {
|
||||
httpOnly: true,
|
||||
secure: isHttps,
|
||||
sameSite: "lax",
|
||||
path: "/api/marketplace/callback",
|
||||
path: "/", // __Host- prefix requires path="/" per RFC 6265bis
|
||||
maxAge: 60 * 10 // 10 minutes
|
||||
});
|
||||
|
||||
@@ -34,7 +34,7 @@ export async function GET(req: NextRequest) {
|
||||
httpOnly: true,
|
||||
secure: isHttps,
|
||||
sameSite: "lax",
|
||||
path: "/api/marketplace/callback",
|
||||
path: "/", // __Host- prefix requires path="/" per RFC 6265bis
|
||||
maxAge: 60 * 10 // 10 minutes
|
||||
});
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ import { NextResponse } from "next/server";
|
||||
import type { NextRequest } from "next/server";
|
||||
import { auth } from "@/lib/auth";
|
||||
import { issueMarketplaceToken } from "@/lib/marketplace/marketplaceToken";
|
||||
import type { MarketplaceSessionToken } from "@worldwideview/wwv-plugin-sdk";
|
||||
import { grantTokenLimiter } from "@/lib/rateLimiters";
|
||||
import { getClientIp } from "@/lib/rateLimit";
|
||||
import { isPluginInstallEnabled, isDemo, isDemoAdmin } from "@/core/edition";
|
||||
@@ -54,9 +55,9 @@ export async function GET(request: NextRequest) {
|
||||
const origin = getRequestOrigin(request);
|
||||
const loginUrl = new URL("/login", origin);
|
||||
|
||||
// Construct a relative path for callback to ensure it redirects back to the identical host
|
||||
const callbackPath = request.nextUrl.pathname + request.nextUrl.search;
|
||||
loginUrl.searchParams.set("callbackUrl", callbackPath);
|
||||
// Construct a relative path for `next` to ensure it redirects back to the identical host
|
||||
const nextPath = request.nextUrl.pathname + request.nextUrl.search;
|
||||
loginUrl.searchParams.set("next", nextPath);
|
||||
return NextResponse.redirect(loginUrl);
|
||||
}
|
||||
|
||||
@@ -68,7 +69,7 @@ export async function GET(request: NextRequest) {
|
||||
return NextResponse.json({ error: "Invalid or missing redirectTo" }, { status: 400 });
|
||||
}
|
||||
|
||||
const token = await issueMarketplaceToken(session.user.id ?? "");
|
||||
const token: MarketplaceSessionToken = await issueMarketplaceToken(session.user.id ?? "");
|
||||
const dest = new URL(redirectTo);
|
||||
// Token in fragment — never sent to server in logs/referer
|
||||
return NextResponse.redirect(`${dest.toString()}#token=${token}`);
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import type { NextRequest } from "next/server";
|
||||
import { auth } from "@/lib/auth";
|
||||
import { getSupabaseUser } from "@/lib/supabase/server";
|
||||
import { isCloud, isPluginInstallEnabled, isDemo, isDemoAdmin } from "@/core/edition";
|
||||
import { upsertPlugin } from "@/lib/marketplace/repository";
|
||||
import { issueMarketplaceToken } from "@/lib/marketplace/marketplaceToken";
|
||||
import type { MarketplaceSessionToken } from "@worldwideview/wwv-plugin-sdk";
|
||||
import type { PluginManifest } from "@/core/plugins/PluginManifest";
|
||||
import { validateManifest } from "@/core/plugins/validateManifest";
|
||||
import { installLimiter } from "@/lib/rateLimiters";
|
||||
import { getClientIp } from "@/lib/rateLimit";
|
||||
import { isPluginInstallEnabled, isDemo, isDemoAdmin } from "@/core/edition";
|
||||
import { getVerifiedPluginIds } from "@/lib/marketplace/registryClient";
|
||||
import { getRequestOrigin } from "@/lib/origin";
|
||||
|
||||
@@ -50,23 +52,38 @@ export async function GET(request: NextRequest) {
|
||||
const rateLimited = installLimiter.check(getClientIp(request));
|
||||
if (rateLimited) return rateLimited;
|
||||
|
||||
const session = await auth();
|
||||
// Auth: cloud edition uses Supabase session; local/demo uses NextAuth.
|
||||
const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL;
|
||||
const isDummyUrl = !supabaseUrl || supabaseUrl.includes("dummy") || supabaseUrl.includes("xyz.supabase.co");
|
||||
const useSupabaseAuth = isCloud && !isDummyUrl;
|
||||
|
||||
// Not logged in — send to login with this URL as callbackUrl
|
||||
if (!session?.user) {
|
||||
const origin = getRequestOrigin(request);
|
||||
|
||||
const loginUrl = new URL("/login", origin);
|
||||
const callbackPath = request.nextUrl.pathname + request.nextUrl.search;
|
||||
loginUrl.searchParams.set("callbackUrl", callbackPath);
|
||||
return NextResponse.redirect(loginUrl);
|
||||
}
|
||||
|
||||
if (isDemo && !isDemoAdmin(session)) {
|
||||
return NextResponse.json(
|
||||
{ error: "Admin access required on Demo edition" },
|
||||
{ status: 403 }
|
||||
);
|
||||
let userId: string;
|
||||
if (useSupabaseAuth) {
|
||||
const supabaseUser = await getSupabaseUser();
|
||||
if (!supabaseUser) {
|
||||
const origin = getRequestOrigin(request);
|
||||
const loginUrl = new URL("/login", origin);
|
||||
const nextPath = request.nextUrl.pathname + request.nextUrl.search;
|
||||
loginUrl.searchParams.set("next", nextPath);
|
||||
return NextResponse.redirect(loginUrl);
|
||||
}
|
||||
userId = supabaseUser.id;
|
||||
} else {
|
||||
const session = await auth();
|
||||
if (!session?.user) {
|
||||
const origin = getRequestOrigin(request);
|
||||
const loginUrl = new URL("/login", origin);
|
||||
const nextPath = request.nextUrl.pathname + request.nextUrl.search;
|
||||
loginUrl.searchParams.set("next", nextPath);
|
||||
return NextResponse.redirect(loginUrl);
|
||||
}
|
||||
if (isDemo && !isDemoAdmin(session)) {
|
||||
return NextResponse.json(
|
||||
{ error: "Admin access required on Demo edition" },
|
||||
{ status: 403 }
|
||||
);
|
||||
}
|
||||
userId = session.user.id ?? "";
|
||||
}
|
||||
|
||||
const pluginId = searchParams.get("pluginId");
|
||||
@@ -113,7 +130,7 @@ export async function GET(request: NextRequest) {
|
||||
return NextResponse.json({ error: "Install failed" }, { status: 500 });
|
||||
}
|
||||
|
||||
const token = await issueMarketplaceToken(session.user.id ?? "");
|
||||
const token: MarketplaceSessionToken = await issueMarketplaceToken(userId);
|
||||
const successUrl = new URL(redirectTo);
|
||||
|
||||
// Unverified plugins need user confirmation on the WWV client side
|
||||
|
||||
@@ -6,6 +6,7 @@ import { GET as connectRoute } from "./connect/route";
|
||||
import { GET as callbackRoute } from "./callback/route";
|
||||
|
||||
vi.mock("openid-client", () => ({
|
||||
Configuration: vi.fn().mockImplementation(function(this: object) { return this; }),
|
||||
randomState: vi.fn(() => "mock-state"),
|
||||
randomPKCECodeVerifier: vi.fn(() => "mock-verifier"),
|
||||
calculatePKCECodeChallenge: vi.fn(() => "mock-challenge"),
|
||||
@@ -55,7 +56,7 @@ describe("PKCE Flow", () => {
|
||||
expect(cookies).toContain("HttpOnly");
|
||||
expect(cookies).toContain("Secure");
|
||||
expect(cookies).toContain("SameSite=lax");
|
||||
expect(cookies).toContain("Path=/api/marketplace/callback");
|
||||
expect(cookies).toContain("Path=/"); // __Host- prefix requires Path=/ per RFC 6265bis
|
||||
// Check __Host- prefix if in production (assuming https testing context)
|
||||
expect(cookies).toMatch(/__Host-pkce_verifier/);
|
||||
});
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { transliterate } from "@/lib/utils/transliterate";
|
||||
|
||||
// Server-side cache: keyed by place_id, 24-hour TTL (place geometry is stable)
|
||||
const cache = new Map<string, { data: unknown; expiresAt: number }>();
|
||||
@@ -50,7 +51,7 @@ export async function GET(request: Request) {
|
||||
const result = {
|
||||
lat: location.lat,
|
||||
lon: location.lng,
|
||||
name: data.result.name,
|
||||
name: transliterate(data.result.name ?? ""),
|
||||
types: data.result.types || [],
|
||||
viewport: data.result.geometry?.viewport || null,
|
||||
};
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { transliterate } from "@/lib/utils/transliterate";
|
||||
|
||||
// Server-side cache: keyed by normalised input, 1-hour TTL
|
||||
const cache = new Map<string, { data: unknown; expiresAt: number }>();
|
||||
@@ -44,10 +45,10 @@ export async function GET(request: Request) {
|
||||
}
|
||||
|
||||
const predictions = data.predictions.map((p: any) => ({
|
||||
description: p.description,
|
||||
description: transliterate(p.description ?? ""),
|
||||
placeId: p.place_id,
|
||||
mainText: p.structured_formatting?.main_text || p.description,
|
||||
secondaryText: p.structured_formatting?.secondary_text || "",
|
||||
mainText: transliterate(p.structured_formatting?.main_text || p.description),
|
||||
secondaryText: transliterate(p.structured_formatting?.secondary_text || ""),
|
||||
types: p.types,
|
||||
}));
|
||||
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { WEATHER_LAYERS, type WeatherLayer } from "@/lib/weatherLayers";
|
||||
|
||||
export const revalidate = 3600;
|
||||
|
||||
const LAYER_META: Record<WeatherLayer, { name: string; description: string }> = {
|
||||
clouds_new: { name: "Clouds", description: "Cloud coverage" },
|
||||
precipitation_new: { name: "Precipitation", description: "Rain and snow" },
|
||||
pressure_new: { name: "Sea Level Pressure", description: "Atmospheric pressure" },
|
||||
wind_new: { name: "Wind Speed", description: "Wind speed and direction" },
|
||||
temp_new: { name: "Temperature", description: "Surface temperature" },
|
||||
};
|
||||
|
||||
const LAYERS = WEATHER_LAYERS.map((id) => ({ id, ...LAYER_META[id] }));
|
||||
|
||||
export async function GET() {
|
||||
const configured = !!process.env.OPENWEATHERMAP_API_KEY;
|
||||
|
||||
return NextResponse.json({
|
||||
configured,
|
||||
tileUrlTemplate: configured ? "/api/weather/tile/{z}/{x}/{y}?layer={layer}" : null,
|
||||
layers: LAYERS,
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { WEATHER_LAYERS, isValidWeatherLayer } from "@/lib/weatherLayers";
|
||||
|
||||
export const revalidate = 600;
|
||||
|
||||
const MAX_ZOOM = 18;
|
||||
|
||||
function isValidTileCoord(value: string, zoom?: number): boolean {
|
||||
const n = Number(value);
|
||||
if (!Number.isInteger(n) || n < 0) return false;
|
||||
if (zoom !== undefined) {
|
||||
if (n >= Math.pow(2, zoom)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function isValidZoom(value: string): boolean {
|
||||
const n = Number(value);
|
||||
return Number.isInteger(n) && n >= 0 && n <= MAX_ZOOM;
|
||||
}
|
||||
|
||||
export async function GET(
|
||||
req: NextRequest,
|
||||
{ params }: { params: Promise<{ z: string; x: string; y: string }> },
|
||||
) {
|
||||
const { z, x, y } = await params;
|
||||
const layer = req.nextUrl.searchParams.get("layer");
|
||||
|
||||
if (!layer || !isValidWeatherLayer(layer)) {
|
||||
return NextResponse.json(
|
||||
{ error: `Invalid layer. Must be one of: ${WEATHER_LAYERS.join(", ")}` },
|
||||
{ status: 400 },
|
||||
);
|
||||
}
|
||||
|
||||
if (!isValidZoom(z)) {
|
||||
return NextResponse.json(
|
||||
{ error: "Invalid tile coordinates" },
|
||||
{ status: 400 },
|
||||
);
|
||||
}
|
||||
|
||||
const zNum = Number(z);
|
||||
if (!isValidTileCoord(x, zNum) || !isValidTileCoord(y, zNum)) {
|
||||
return NextResponse.json(
|
||||
{ error: "Invalid tile coordinates" },
|
||||
{ status: 400 },
|
||||
);
|
||||
}
|
||||
|
||||
const apiKey = process.env.OPENWEATHERMAP_API_KEY;
|
||||
if (!apiKey) {
|
||||
return NextResponse.json(
|
||||
{ error: "Weather API not configured" },
|
||||
{ status: 503 },
|
||||
);
|
||||
}
|
||||
|
||||
const tileUrl = `https://tile.openweathermap.org/map/${layer}/${z}/${x}/${y}.png?appid=${apiKey}`;
|
||||
|
||||
try {
|
||||
const response = await fetch(tileUrl, {
|
||||
headers: { "User-Agent": "WorldWideView/1.0" },
|
||||
next: { revalidate },
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
return NextResponse.json(
|
||||
{ error: "Failed to fetch weather tile" },
|
||||
{ status: 502 },
|
||||
);
|
||||
}
|
||||
|
||||
const buffer = await response.arrayBuffer();
|
||||
|
||||
return new Response(buffer, {
|
||||
status: 200,
|
||||
headers: {
|
||||
"Content-Type": "image/png",
|
||||
"Cache-Control": "public, max-age=600, stale-while-revalidate=300",
|
||||
},
|
||||
});
|
||||
} catch {
|
||||
return NextResponse.json(
|
||||
{ error: "Failed to fetch weather tile" },
|
||||
{ status: 502 },
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -2134,3 +2134,30 @@ body.is-dragging-bottom-panel .bottom-panel {
|
||||
gap: 12px;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
/* ─── Legal Footer ────────────────────────────────────────── */
|
||||
.legal-footer {
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
z-index: 10;
|
||||
padding: 4px var(--space-lg, 1.5rem);
|
||||
background: rgba(9, 9, 11, 0.7);
|
||||
border-top: 1px solid var(--border-subtle);
|
||||
display: flex;
|
||||
gap: var(--space-lg, 1.5rem);
|
||||
justify-content: center;
|
||||
font-size: 11px;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.legal-footer a {
|
||||
color: var(--text-muted);
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.legal-footer a:hover {
|
||||
color: var(--text-secondary);
|
||||
text-decoration: underline;
|
||||
}
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
import type { Metadata, Viewport } from "next";
|
||||
import Script from "next/script";
|
||||
import { Analytics } from "@vercel/analytics/next";
|
||||
import "./globals.css";
|
||||
import "@/styles/hud-animations.css";
|
||||
import { LegalFooter } from "@/components/layout/LegalFooter";
|
||||
|
||||
export const viewport: Viewport = {
|
||||
width: "device-width",
|
||||
@@ -53,7 +53,6 @@ export default function RootLayout({
|
||||
</head>
|
||||
<body suppressHydrationWarning>
|
||||
{children}
|
||||
{process.env.VERCEL && <Analytics />}
|
||||
{process.env.NEXT_PUBLIC_WWV_ANALYTICS === "true" && (
|
||||
<Script
|
||||
src="https://analytics.worldwideview.dev/script.js"
|
||||
@@ -61,6 +60,7 @@ export default function RootLayout({
|
||||
strategy="afterInteractive"
|
||||
/>
|
||||
)}
|
||||
<LegalFooter />
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
|
||||
Loaded 100 of 203 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user