5.4 KiB
Configuration
Precedence and lifecycle
Configuration is validated by ConfigSchema in src/config/index.ts.
DATABASE_PATHidentifies the database before application settings can be read.- If
app_configexists, the application-owned configuration is loaded from SQLite. - Otherwise,
config.yamlis loaded once and the validated application-owned subset is seeded into SQLite. - Environment-owned secrets and database location are injected on every start.
After the initial seed, editing config.yaml does not replace an existing app_config row. Use the authenticated settings/API workflow or a deliberate database migration. The config route validates the complete result before saving.
Environment-owned values
| Variable | Required | Purpose |
|---|---|---|
OPENROUTER_API_KEY |
Yes | OpenRouter authentication. |
WEB_DASHBOARD_TOKEN |
When web is enabled | Administrator UI/API credential. |
DATABASE_PATH |
No | SQLite location; defaults to ./data/reddit-bot.db. |
REDDIT_BOT_AGENT_READ_TOKEN |
No | Read-only API/SSE bearer credential. |
REDDIT_BOT_AGENT_CONTROL_TOKEN |
No | Read plus versioned control/job bearer credential. |
REDDIT_BOT_API_URL |
MCP only | Base URL; defaults to http://127.0.0.1:3000. |
REDDIT_BOT_AGENT_TOKEN |
MCP only | Preferred MCP bearer credential override. |
Never document real values. .env is ignored and may contain production credentials; do not print or blindly source it.
Application sections
reddit
subreddits: at least one item withname,enabled,type, optionalweight,tone, optional scripted opener, and conversation policy.pollIntervalMs: legacy/scheduled polling cadence.userAgent: Reddit JSON request identifier.targetGenders: allowed parsed values.filterSellers,sellerKeywords,sellerDomains: seller policy inputs.prioritizeRecentPosts,recentWindowMinutes: recency/fallback behavior.maxReadyCandidates: hard ceiling for the active candidate target; valid range 1–500. Runtime lowers the actual target to what authenticated running accounts can send withinrecentWindowMinutesunder current rolling-hour and message-spacing limits.
Subreddit type is image or chat. Conversation policy contains mode, maxAutomatedTurns, and rapportTurnsBeforeMediaAsk; hybrid rapport turns must be lower than the maximum.
openrouter
Contains image/chat primary and fallback models plus the analysis, message, and chat-opener prompt templates. The API key is environment-only. Model fallback and prompt changes affect cost, behavior, and experiment attribution and need focused tests plus operator-visible metadata.
rateLimit
minDelayBetweenMessagesMs;maxMessagesPerHour;jitterMs.
These are per account. Reddit JSON request pacing is separately controlled by RedditRequestCoordinator and is process-global.
browser
sessionDir: root for persistent account browser profiles.dryRun: when true, candidate preparation may run but remote sends must not.
Treat changing dryRun from true to false as enabling a real side effect.
database
Contains path, but runtime ownership is DATABASE_PATH, not the persisted application config.
media
Controls periodic sync enablement and interval. Media work remains authentication-bound.
strategies and chatStrategies
Each has exploration rate, minimum mature samples, response window, and weighted variants. Variants include an ID and prompt override. Image and chat sources use separate sections so their results are not compared as one experiment.
web
Controls enabled state, port, optional tokens after environment injection, and dangerous debug endpoint enablement. Production secrets should never live in YAML.
Runtime-editable subset
The dashboard/API exposes a deliberate subset: rate limits, dry-run, recency and ready-funnel limits, subreddit definitions/conversation behavior, and selected advanced configuration. Shared transport schemas live in packages/api-contracts/src/config.ts; the backend source schema is still the final validator.
When adding a runtime-editable setting, update all of:
ConfigSchemaand defaults.config.yamlseed/example when appropriate.ConfigStorepersistence rules if ownership changes.- Shared request/response schemas.
- The config route's merge/write/read-back behavior.
- Dashboard model/control.
- backend, contract, route, and dashboard tests.
- this document.
Validation and change safety
- Use Zod for every external or persisted shape.
- Reject unknown transport fields with strict contracts.
- Validate relationships (not just types), such as the hybrid turn constraint.
- Do not log the full config because it contains injected secrets in memory.
- Configuration that affects running account objects may not be fully hot-reloaded; inspect the owning service before claiming immediate effect.
- A production
PUT /api/configshould be followed by an authenticated GET read-back. Do not infer persistence from a 2xx alone. - A subreddit listing 404 is persisted as disabled so every account runtime stops polling it.
Local safe setup
Install dependencies and run builds/tests without starting the application. If a local backend is explicitly needed, use a dry-run configuration and verify the database path/port before starting. Importing a real session or calling the start control is a separate live-capable action.