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>
This commit is contained in:
1 parent
3a40651930
commit
14d92e14ee
38 files changed
+724
-140
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import type Database from 'better-sqlite3';
|
||||
import type { PhysiqueTargeting } from '../config/index.js';
|
||||
import type { RedditPost } from '../reddit/api.js';
|
||||
import { allowsSending, parseBotMode, type BotMode } from '../services/bot-mode.js';
|
||||
import { evaluatePhysiqueTargeting } from '../services/physique-targeting.js';
|
||||
import type { ProcessedPost } from '../services/processor.js';
|
||||
|
||||
@@ -429,20 +430,33 @@ export class CandidateQueueRepository {
|
||||
}
|
||||
}
|
||||
|
||||
/** Persists the operator's intended pause/run state across container restarts. */
|
||||
/** Persists the operator's intended run/scan/stop state across container restarts. */
|
||||
export class RuntimeStateRepository {
|
||||
constructor(private readonly db: Database.Database) {}
|
||||
|
||||
getBotMode(): BotMode {
|
||||
const row = this.db.prepare('SELECT bot_running, bot_mode FROM runtime_state WHERE id = 1')
|
||||
.get() as { bot_running: number; bot_mode: string | null } | undefined;
|
||||
if (!row) return 'stopped';
|
||||
// `bot_mode` is null for rows written by an older build; fall back to the boolean.
|
||||
return parseBotMode(row.bot_mode, row.bot_running === 1 ? 'running' : 'stopped');
|
||||
}
|
||||
|
||||
setBotMode(mode: BotMode, now: number = Date.now()): void {
|
||||
this.db.prepare(`
|
||||
INSERT INTO runtime_state (id, bot_running, bot_mode, updated_at) VALUES (1, ?, ?, ?)
|
||||
ON CONFLICT(id) DO UPDATE SET
|
||||
bot_running = excluded.bot_running,
|
||||
bot_mode = excluded.bot_mode,
|
||||
updated_at = excluded.updated_at
|
||||
`).run(allowsSending(mode) ? 1 : 0, mode, now);
|
||||
}
|
||||
|
||||
isBotRunning(): boolean {
|
||||
const row = this.db.prepare('SELECT bot_running FROM runtime_state WHERE id = 1')
|
||||
.get() as { bot_running: number } | undefined;
|
||||
return row?.bot_running === 1;
|
||||
return allowsSending(this.getBotMode());
|
||||
}
|
||||
|
||||
setBotRunning(running: boolean, now: number = Date.now()): void {
|
||||
this.db.prepare(`
|
||||
INSERT INTO runtime_state (id, bot_running, updated_at) VALUES (1, ?, ?)
|
||||
ON CONFLICT(id) DO UPDATE SET bot_running = excluded.bot_running, updated_at = excluded.updated_at
|
||||
`).run(running ? 1 : 0, now);
|
||||
this.setBotMode(running ? 'running' : 'stopped', now);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user