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:
Jamie BruntonandClaude Opus 5 committed 2026-08-11 10:16:24 +01:00
1 parent 3a40651930
commit 14d92e14ee
38 files changed
+724 -140

No files matched your search

@@ -1,5 +1,6 @@
import { useState } from 'react';
import { useStatsQuery, useSetRunningMutation } from '../api/queries.js';
import { useStatsQuery, useSetModeMutation } from '../api/queries.js';
import type { BotMode } from '../api/contracts.js';
import { ConfirmationDialog } from '../components/confirmation-dialog.js';
import { useSyncStatusQuery } from '../features/operations/operations-queries.js';
import { useLoginStatusQuery } from '../features/settings/settings-queries.js';
@@ -12,15 +13,15 @@ export function ShellStatusPanel() {
const reddit = useLoginStatusQuery();
const sync = useSyncStatusQuery();
const realtime = useDashboardRealtime();
const control = useSetRunningMutation();
const [confirming, setConfirming] = useState<'start' | 'stop' | null>(null);
const control = useSetModeMutation();
const [confirming, setConfirming] = useState<BotMode | null>(null);
const status = deriveShellStatus({ stats: stats.data, reddit: reddit.data, sync: sync.data, realtime: realtime.connection });
return <>
<section aria-label="Platform status" className="shell-status">
<strong>{status.bot}</strong><span>{status.reddit}</span><span>{status.realtime}</span><span>{status.sync}</span>
{status.cooldown ? <span className="shell-warning">Cooldown: {status.cooldown}</span> : null}
<button aria-label={`${status.controlAction === 'start' ? 'Start' : 'Stop'} bot from global status`} className={status.controlAction === 'start' ? 'button primary' : 'button danger'} disabled={status.controlDisabled || control.isPending} onClick={() => setConfirming(status.controlAction)} type="button">{status.controlAction === 'start' ? 'Start bot' : 'Stop bot'}</button>
<button aria-label={`${status.controlAction === 'running' ? 'Start' : 'Stop'} bot from global status`} className={status.controlAction === 'running' ? 'button primary' : 'button danger'} disabled={status.controlDisabled || control.isPending} onClick={() => setConfirming(status.controlAction)} type="button">{status.controlAction === 'running' ? 'Start bot' : 'Stop bot'}</button>
</section>
{confirming ? <ConfirmationDialog action={confirming} isPending={control.isPending} onCancel={() => setConfirming(null)} onConfirm={() => control.mutate(confirming === 'start', { onSuccess: () => setConfirming(null) })} /> : null}
{confirming ? <ConfirmationDialog action={confirming} isPending={control.isPending} onCancel={() => setConfirming(null)} onConfirm={() => control.mutate(confirming, { onSuccess: () => setConfirming(null) })} /> : null}
</>;
}
+13 -4
View File
@@ -1,7 +1,14 @@
import type { RealtimeConnectionSnapshot } from '../features/operations/realtime-client.js';
import type { BotMode } from '../api/contracts.js';
const MODE_LABEL: Record<BotMode, string> = {
running: 'Running',
scan: 'Scanning',
stopped: 'Stopped',
};
interface ShellStatusInput {
stats?: { isRunning: boolean; dryRunMode: boolean; invitationCooldown: { reason: string } | null };
stats?: { mode: BotMode; dryRunMode: boolean; invitationCooldown: { reason: string } | null };
reddit?: { ready: boolean; loggedIn?: boolean; status?: string; error?: string };
realtime: RealtimeConnectionSnapshot;
sync?: { syncing: boolean; syncingKind?: string | null };
@@ -13,7 +20,7 @@ export interface ShellStatus {
realtime: string;
cooldown: string | null;
sync: string;
controlAction: 'start' | 'stop';
controlAction: BotMode;
controlDisabled: boolean;
}
@@ -28,12 +35,14 @@ export function deriveShellStatus(input: ShellStatusInput): ShellStatus {
? input.reddit.loggedIn ? `Reddit ${input.reddit.status ?? 'authenticated'}` : 'Reddit login required'
: 'Reddit session unavailable';
return {
bot: stats ? `${stats.isRunning ? 'Running' : 'Stopped'}${stats.dryRunMode ? ' (dry run)' : ''}` : 'Bot state unavailable',
bot: stats ? `${MODE_LABEL[stats.mode]}${stats.dryRunMode ? ' (dry run)' : ''}` : 'Bot state unavailable',
reddit,
realtime,
cooldown: stats?.invitationCooldown?.reason ?? null,
sync: input.sync?.syncing ? `${sentence(input.sync.syncingKind ?? 'unknown')} sync active` : 'No active sync',
controlAction: stats?.isRunning ? 'stop' : 'start',
// The header's single control is the opposite of wherever we are now;
// scan mode's natural next step is a full start.
controlAction: stats?.mode === 'running' ? 'stopped' : 'running',
controlDisabled: stats === undefined,
};
}