Files
RedditBot/src/services/bot-mode.ts
T
Jamie BruntonandClaude Opus 5 14d92e14ee feat: add scan mode so conversations stay in sync without sending
Stopping the bot previously halted conversation syncing too. On the
multi-account path the run-flag check sat above both the reply-sync and
response-check branches, so a stop left only MediaSyncService's coarse
30-minute chat refresh. The legacy single-account path did the opposite
and kept syncing while stopped — one boolean meaning two things.

Replace the boolean with an explicit three-way mode:

  running — discover, screen, send, automate replies
  scan    — refresh chats, detect replies, check responses; send nothing
             and discover nothing; actionable replies surface as backlog
  stopped — everything halts, including background media sync

scan differs from browser.dryRun, which still discovers and pays for AI
screening before suppressing the send.

The mode persists in runtime_state.bot_mode; a migration backfills it
from bot_running, and rows written by an older build still read
correctly. Both loops now gate on the mode, the account runtime loop
reconciles background media sync on transitions only, and the dashboard
and agent API expose all three states.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-11 10:16:24 +01:00

49 lines
1.7 KiB
TypeScript

/**
* The operator's intended runtime posture.
*
* - `running` — discover candidates, screen them, send outbound messages and
* automate replies.
* - `scan` — keep conversations in sync (chat refresh, reply detection,
* response checking) but send nothing and start no new outreach. Actionable
* replies are surfaced as backlog for a human instead of being answered.
* - `stopped` — everything halts.
*
* `scan` differs from `browser.dryRun`: dry run still discovers and screens
* candidates (and pays for the AI screening), it just suppresses the send.
*/
export type BotMode = 'running' | 'scan' | 'stopped';
export const BOT_MODES: readonly BotMode[] = ['running', 'scan', 'stopped'];
export function isBotMode(value: unknown): value is BotMode {
return typeof value === 'string' && (BOT_MODES as readonly string[]).includes(value);
}
/** Falls back to `stopped` so an unreadable persisted value never auto-sends. */
export function parseBotMode(value: unknown, fallback: BotMode = 'stopped'): BotMode {
return isBotMode(value) ? value : fallback;
}
/** Outbound messages and automated replies. */
export function allowsSending(mode: BotMode): boolean {
return mode === 'running';
}
/** Subreddit scanning, AI screening and candidate dispatch. */
export function allowsDiscovery(mode: BotMode): boolean {
return mode === 'running';
}
/** Chat refresh, reply detection and response checking. */
export function allowsConversationSync(mode: BotMode): boolean {
return mode === 'running' || mode === 'scan';
}
export function describeBotMode(mode: BotMode): string {
switch (mode) {
case 'running': return 'Running';
case 'scan': return 'Scanning';
case 'stopped': return 'Stopped';
}
}