Overview
Thethepopebot/config export provides Next.js configuration helpers and server initialization hooks.
thepopebot/config
Next.js config wrapper with framework-specific settings.Import
Function
Wraps user’s Next.js config with Pope Bot framework requirements
next.config.mjs:
What It Does
- Enables instrumentation - Allows server startup hooks for cron scheduling
- Transpiles package - Ensures
thepopebotpackage is bundled correctly - Sets environment variables - Exposes feature flags to browser
- Configures SQLite - Marks database packages as server-external
- Custom build directory - Respects
NEXT_BUILD_DIRenv var
Configuration Options
Build output directory (default:
.next, override with NEXT_BUILD_DIR)Adds
thepopebot to package transpilation listSet to
'true' if code workspaces are enabled (requires CLAUDE_CODE_OAUTH_TOKEN + BETA)Set to
'true' if voice features are enabled (requires ASSEMBLYAI_API_KEY)Marks
better-sqlite3 and drizzle-orm as external (prevents bundling issues)thepopebot/instrumentation
Server startup hook for initializing cron jobs and database.Import
Function
Called once when Next.js server starts. Initializes database, loads environment, starts cron scheduler.
instrumentation.js:
What It Does
- Loads
.env- Ensures environment variables are available - Initializes database - Creates SQLite tables if needed
- Starts cron scheduler - Loads
config/CRONS.jsonand schedules jobs
Runtime Guard
Only runs in Node.js runtime (skips Edge runtime):Environment Variables
The config module reads these variables:Custom build output directory (default:
.next)Enables code workspace feature when combined with
BETA=trueSet to
true to enable beta features (code workspaces)Enables voice features when present
Why Instrumentation?
Next.js 15+ supports instrumentation hooks for server startup. This is the cleanest way to:- Load cron jobs before handling requests
- Initialize database schema atomically
- Avoid race conditions from multiple workers
Cron Scheduling
Theregister() function calls startCron(), which:
- Reads
config/CRONS.json - Parses cron expressions via
node-cron - Schedules tasks (agent jobs, commands, webhooks)
- Runs continuously in background
Database Initialization
CallsinitDatabase() from lib/db/index.js:
- Connects to SQLite (
data/thepopebot.sqlite) - Runs migrations from
drizzle/directory - Creates tables if they don’t exist
- Returns database connection
DATABASE_PATH env var.
Example Setup
next.config.mjs:Related
- Cron Jobs - Scheduled task configuration
- Database Schema - SQLite structure and migrations
- Next.js Instrumentation docs