firebase-prod-campaigns
Guide and workflow for Firebase Production Campaign Database Access. Use when you need Firebase Production Campaign Database Access.
What this skill does
# Firebase Production Campaign Database Access
## Overview
This skill documents how to query the **production Firestore database** for WorldArchitect.AI campaigns and user data.
## CRITICAL: Campaign Lookup
**Campaigns are NESTED under users, NOT at root level!**
```python
# WRONG - This queries the wrong collection (test data only):
db.collection('campaigns').document('VqqJLpABua9bvAG4ArTg')
# CORRECT - Campaigns are nested under user UID:
db.collection('users').document(uid).collection('campaigns').document('VqqJLpABua9bvAG4ArTg')
```
### Quick Lookup for Known Campaign ID
```python
# 1. Get user UID from email
user_record = auth.get_user_by_email('[email protected]')
uid = user_record.uid # e.g., 'vnLp2G3m21PJL6kxcuAqmWSOtm73'
# 2. Query nested path
doc = db.collection('users').document(uid).collection('campaigns').document('CAMPAIGN_ID').get()
```
## Database Structure
```
Firestore Database: worldarchitecture-ai
├── campaigns/ # ← WRONG: Only test data here (5 campaigns)
│ └── {test_campaign_id}/
│
└── users/ # ← CORRECT: Real user data here (146+ campaigns)
└── {Firebase_Auth_UID}/ # e.g., vnLp2G3m21PJL6kxcuAqmWSOtm73
└── campaigns/
└── {campaign_id}/ # e.g., VqqJLpABua9bvAG4ArTg
├── title # "Nocturne post bg3 zhent"
├── created_at
├── last_played
├── world_name
├── game_states/ # ← SUBCOLLECTION for game state
│ └── current_state/ # Main game state document
│ ├── player_character_data
│ ├── combat_state
│ ├── npc_data
│ └── custom_campaign_state/
│ └── god_mode_directives[] # ← Persisted rules
└── story/
└── {entry_id}/
├── actor (user/gemini)
├── text
└── timestamp
```
## IMPORTANT: Game State Location
**Game state is in a SUBCOLLECTION, not a field!**
```python
# WRONG - game_state is NOT a field on the campaign document:
campaign = db.collection('users').document(uid).collection('campaigns').document(campaign_id).get()
game_state = campaign.to_dict().get('game_state') # Returns empty!
# CORRECT - game_state is in a subcollection called 'game_states':
game_state_ref = db.collection('users').document(uid).collection('campaigns').document(campaign_id).collection('game_states').document('current_state')
game_state = game_state_ref.get().to_dict()
```
### Querying God Mode Directives
```python
# Get god mode directives for a campaign
game_state_ref = campaign_ref.collection('game_states').document('current_state')
game_state = game_state_ref.get().to_dict()
custom_campaign_state = game_state.get('custom_campaign_state', {})
god_mode_directives = custom_campaign_state.get('god_mode_directives', [])
for directive in god_mode_directives:
if isinstance(directive, dict):
print(f"Rule: {directive.get('rule')}")
print(f"Added: {directive.get('added')}")
```
### Using the Directive Query Script
```bash
# List all directives for a campaign
WORLDAI_DEV_MODE=true \
WORLDAI_GOOGLE_APPLICATION_CREDENTIALS=~/serviceAccountKey.json \
python scripts/query_directives.py wBoMKQuMnvLfyjTFTBHd
# Debug why a directive wasn't saved
python scripts/query_directives.py wBoMKQuMnvLfyjTFTBHd --debug-missing "power scaling"
# Manually add a missing directive
python scripts/query_directives.py wBoMKQuMnvLfyjTFTBHd --add "Level 9 is extremely powerful - never use 'mere' or 'modest'"
```
## Debugging Missing God Mode Directives
When a user's god mode request doesn't result in a saved directive, follow this process:
### 1. How Directives Are Saved
The LLM must return a `directives` field in its structured JSON response:
```json
{
"god_mode_response": "Acknowledged...",
"directives": {
"add": ["Rule to remember going forward"],
"drop": ["Rule to stop following"]
}
}
```
**Processing code:** `mvp_site/world_logic.py:1585-1667`
**Prompt instructions:** `mvp_site/prompts/god_mode_instruction.md:72-96`
### 2. Common Failure Modes
| Symptom | Cause | Solution |
|---------|-------|----------|
| Directive acknowledged but not saved | LLM returned `god_mode_response` but no `directives.add` | Check raw LLM response |
| Directive in `dm_notes` only | LLM put rule in `state_updates.debug_info.dm_notes` | `dm_notes` are now injected into future prompts as part of the system prompt |
| Empty `god_mode_directives` list | No directives ever saved | Check story entries for god mode responses |
### 3. Debugging Process
```python
# 1. Check if directives exist
custom_state = game_state.get('custom_campaign_state', {})
directives = custom_state.get('god_mode_directives', [])
print(f"Saved directives: {len(directives)}")
# 2. Find god mode story entries
story_ref = campaign_ref.collection('story')
for entry in story_ref.order_by('timestamp', direction='DESCENDING').limit(100).stream():
data = entry.to_dict()
if data.get('actor') == 'gemini' and 'God Mode active' in data.get('text', ''):
debug_info = data.get('debug_info', {})
raw_response = debug_info.get('raw_response_text', '')
if raw_response:
parsed = json.loads(raw_response)
print(f"Entry {entry.id}:")
print(f" Has directives field: {'directives' in parsed}")
if 'directives' not in parsed:
print(f" State updates: {parsed.get('state_updates', {})}")
```
### 4. Key Insight: `dm_notes` vs `directives`
- **`dm_notes`**: Internal notes stored in `state_updates.debug_info.dm_notes`. ARE injected into future system prompts (as of this PR) to provide important context the LLM wrote but did not formally save as directives.
- **`directives`**: Persisted rules stored in `god_mode_directives[]`. ARE injected into system prompts via `agent_prompts.py:669-753`.
If the LLM writes to `dm_notes` instead of `directives`, the rule won't persist as a formal directive.
## User Identification
- Users are identified by **Firebase Auth UID**, NOT email
- Primary user: `[email protected]` → UID: `vnLp2G3m21PJL6kxcuAqmWSOtm73`
- Test user: `[email protected]`
- Use `auth.get_user_by_email()` to convert email → UID
## Prerequisites
### Environment Variables
```bash
export WORLDAI_DEV_MODE=true
export WORLDAI_GOOGLE_APPLICATION_CREDENTIALS=~/serviceAccountKey.json
```
### Service Account Key
Location: `~/serviceAccountKey.json`
Project: `worldarchitecture-ai`
## Using campaign_manager.py
The recommended tool for production queries is `scripts/campaign_manager.py`.
### Find User by Email
```bash
WORLDAI_DEV_MODE=true \
WORLDAI_GOOGLE_APPLICATION_CREDENTIALS=~/serviceAccountKey.json \
python scripts/campaign_manager.py find-user [email protected]
```
### Analyze User Activity (with token/cost estimation)
```bash
# Analyze last 3 months
WORLDAI_DEV_MODE=true \
WORLDAI_GOOGLE_APPLICATION_CREDENTIALS=~/serviceAccountKey.json \
python scripts/campaign_manager.py analytics [email protected]
# Specific month
WORLDAI_DEV_MODE=true \
WORLDAI_GOOGLE_APPLICATION_CREDENTIALS=~/serviceAccountKey.json \
python scripts/campaign_manager.py analytics [email protected] --month 2025-11
```
### Query Campaigns by Name
```bash
WORLDAI_DEV_MODE=true \
WORLDAI_GOOGLE_APPLICATION_CREDENTIALS=~/serviceAccountKey.json \
python scripts/campaign_manager.py query <UID> "Campaign Name"
```
## Direct Python Query (Ad-hoc)
For custom queries, use this pattern:
```python
import sys
sys.path.insert(0, 'mvp_site')
# CRITICAL: Apply clock skew patch BEFORE importing Firebase
from mvp_site.clock_skew_credentials import apply_clock_skew_patch
apply_clock_skew_patch()
import firebase_admin
from firebase_admin import auth, firestore, credentials
import os
# Initialize with explicit crRelated in Ads & Marketing
ads
IncludedMulti-platform paid advertising audit and optimization skill. Analyzes Google, Meta, YouTube, LinkedIn, TikTok, Microsoft, and Apple Ads. 250+ checks with scoring, parallel agents, industry templates, and AI creative generation.
banana
IncludedAI image generation Creative Director powered by Google Gemini Nano Banana models. Use this skill for ANY request involving image creation, editing, visual asset production, or creative direction. Triggers on: generate an image, create a photo, edit this picture, design a logo, make a banner, visual for my anything, and all /banana commands. Handles text-to-image, image editing, multi-turn creative sessions, batch workflows, and brand presets.
rpg-migration-analyzer
IncludedAnalyzes legacy RPG (Report Program Generator) programs from AS/400 and IBM i systems for migration to modern Java applications. Extracts business logic from RPG III/IV/ILE source code, identifies data structures (D-specs), file operations (F-specs), program dependencies (CALLB/CALLP), and converts RPG constructs to Java equivalents. Generates migration reports, complexity estimates, and Java implementation strategies with POJO classes, JPA entities, and service methods. Use when modernizing AS/400 or IBM i legacy systems, analyzing RPG source files (.rpg, .rpgle, .RPGLE), converting RPG to Java, mapping data specifications to Java classes, planning legacy system migration, or when user mentions RPG analysis, Report Program Generator, RPG III/IV/ILE, AS/400 modernization, IBM i migration, packed decimal conversion, or mainframe application rewrite.
brand-library-architect
IncludedBuild a complete brand library for a product — visual asset render pipeline, brand documentation set (BRAND, COPY, MANIFESTO, BIOS, FAQ, GLOSSARY, TONE, PRICING), open-source convention files (README, CONTRIBUTING, SECURITY, CODE_OF_CONDUCT), and a self-contained press kit. This skill should be used when the user asks to "build a brand library / brand kit / press kit / brand assets" for a product, "set up a brand library workflow," "create a positioning manifesto plus visual identity," or any combination of brand documentation + visual asset pipeline. Apply phase-by-phase or run end-to-end. Templates are product-agnostic and use {{TOKEN}} placeholders the skill prompts the user to fill.
writing-tech-post
IncludedAuthors engineering blog posts end-to-end: launch deep-dives, incident postmortems, architecture migrations, performance case studies, tutorials, AI/agent system writeups, security disclosures, and research-to-product translations. Picks the correct archetype, plans the abstraction ladder, enforces an evidence cadence (diagrams, benchmarks, profiles, traces, code, ablations), tunes voice against publisher house styles (Datadog, Vercel, GitHub, AWS, Meta, Cloudflare, Jane Street), and runs a pre-publish gate for narrative momentum and disclosure ethics. Use when drafting a new engineering post, restructuring a draft that feels flat, deciding which evidence form belongs where, validating that depth and product context are balanced, or preparing a postmortem, migration, or performance narrative for external publication. Do not use for API reference documentation, README authoring, marketing copy, release notes, generic SEO content, ghost-written executive thought leadership, or non-engineering long-form essays.
blog-google
IncludedGoogle API integration for blog performance: PageSpeed Insights, CrUX Core Web Vitals with 25-week history, Search Console performance, URL Inspection, Indexing API, GA4 organic traffic, NLP entity analysis for E-E-A-T, YouTube video search for embedding, and Google Ads Keyword Planner. Progressive feature availability based on credential tier (API key, OAuth/service account, GA4, Ads). Shares config with claude-seo at ~/.config/claude-seo/google-api.json. Use when user says "google data", "page speed", "core web vitals", "search console", "indexation", "GA4", "keyword research", "nlp entities", "blog performance", "youtube search", "google api setup".