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,4 +1,5 @@
|
||||
import express from 'express';
|
||||
import type { BotMode } from '../../src/services/bot-mode.js';
|
||||
import type { AddressInfo } from 'node:net';
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import type { WebContext } from '../../src/web/context.js';
|
||||
@@ -6,13 +7,13 @@ import { createControlRouter } from '../../src/web/routes/control.js';
|
||||
|
||||
describe('control route realtime events', () => {
|
||||
it('publishes the authoritative bot state after each successful transition', async () => {
|
||||
let running = false;
|
||||
let mode: BotMode = 'stopped';
|
||||
const bot = vi.fn();
|
||||
const context = {
|
||||
config: { browser: { dryRun: true } },
|
||||
services: { accountAuth: { isFullyAuthenticated: () => true } },
|
||||
getBotRunning: () => running,
|
||||
setBotRunning: (next: boolean) => { running = next; },
|
||||
getBotMode: () => mode,
|
||||
setBotMode: (next: BotMode) => { mode = next; },
|
||||
activity: { push: vi.fn() },
|
||||
logger: { info: vi.fn() },
|
||||
broadcaster: { dashboardEvents: { bot } },
|
||||
@@ -24,12 +25,16 @@ describe('control route realtime events', () => {
|
||||
|
||||
try {
|
||||
expect((await fetch(`http://127.0.0.1:${port}/api/start`, { method: 'POST' })).status).toBe(200);
|
||||
expect(running).toBe(true);
|
||||
expect(bot).toHaveBeenLastCalledWith({ running: true, dryRun: true });
|
||||
expect(mode).toBe('running');
|
||||
expect(bot).toHaveBeenLastCalledWith({ mode: 'running', dryRun: true });
|
||||
|
||||
expect((await fetch(`http://127.0.0.1:${port}/api/scan`, { method: 'POST' })).status).toBe(200);
|
||||
expect(mode).toBe('scan');
|
||||
expect(bot).toHaveBeenLastCalledWith({ mode: 'scan', dryRun: true });
|
||||
|
||||
expect((await fetch(`http://127.0.0.1:${port}/api/stop`, { method: 'POST' })).status).toBe(200);
|
||||
expect(running).toBe(false);
|
||||
expect(bot).toHaveBeenLastCalledWith({ running: false, dryRun: true });
|
||||
expect(mode).toBe('stopped');
|
||||
expect(bot).toHaveBeenLastCalledWith({ mode: 'stopped', dryRun: true });
|
||||
} finally {
|
||||
await new Promise<void>((resolve) => server.close(() => resolve()));
|
||||
}
|
||||
|
||||
@@ -75,6 +75,7 @@ describe('stats route account status', () => {
|
||||
repos: { messages: { getRecent: () => [] } },
|
||||
activity: { recent: () => [], totalProcessed: () => 0 },
|
||||
getBotRunning: () => true,
|
||||
getBotMode: () => 'running',
|
||||
getMessagesThisHour: () => 0,
|
||||
} as unknown as WebContext;
|
||||
const app = express().use('/api', createStatsRouter(context));
|
||||
|
||||
Reference in new issue
Block a user