Let the master dashboard drive this instance; drop the AutoBuyer switch

Three changes that ride together because they touch the same surface.

A control link to the master. lib/master-link.ts dials out to
<master>/ws/instance and holds it open, so the dashboard can trigger a trade or
queue an AutoBuyer run here. Commands call the same functions the local pages
call — runTrade, startScheduler, queueRun — so nothing reaches the broker by a
path the UI does not also use. Reports prefer the socket and fall back to the
existing POST, which keeps older masters working unchanged.

startMasterLink is idempotent, and that matters more than it looks: getClients()
is lazy and starts the link, so the first command re-enters it from inside a
command the live socket is waiting to ack. Tearing the socket down there loses
the ack and reports a trade that actually executed as a failure — which invites
pressing the button twice.

queueRun is lifted out of the automations route so the socket and HTTP share one
copy of the input clamping that decides how many times a purchase fires.

Page capture loses its switch and gains a scope. It now runs every tick, but
only against the active tab of the last-focused window that matches
host_permissions — so it follows the page in front of you and stops when you
switch away, where before it would fall back to any firm tab left open in the
background.

autobuyer_enabled is gone entirely. The AutoBuyer is ready whenever the runner
is; a run happens because someone asked for one. That does mean a queued run
executes as soon as clicker/runner.py claims it, with no second gate — stopping
the runner is now the way to make a machine idle.

Extension to 0.10.0; it needs a manual reload at chrome://extensions.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Brandon Li
2026-08-30 22:31:31 -05:00
co-authored by Claude Opus 5
parent 0ba27161ce
commit 25289cb9b3
16 changed files with 586 additions and 190 deletions
+9 -55
View File
@@ -115,9 +115,7 @@ function withBaseTag(html: string, url: string): string {
}
export default function AutoBuyer() {
const [enabled, setEnabled] = useState(false);
const [capture, setCapture] = useState<Capture | null>(null);
const [busy, setBusy] = useState(false);
const [error, setError] = useState<string | null>(null);
const [view, setView] = useState<'rendered' | 'source'>('source');
// The extension posts a new capture every few seconds, and re-feeding srcDoc would
@@ -137,10 +135,6 @@ export default function AutoBuyer() {
const poll = useCallback(async () => {
try {
const s = await fetch('/api/autobuyer/status', { cache: 'no-store' }).then((r) => r.json());
setEnabled(!!s.enabled);
if (!s.enabled) return;
const url = lastAtRef.current
? `/api/autobuyer/capture?since=${lastAtRef.current}`
: '/api/autobuyer/capture';
@@ -236,24 +230,6 @@ export default function AutoBuyer() {
await pollRuns();
}
async function toggle() {
setBusy(true);
try {
const res = await fetch('/api/autobuyer/status', {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ enabled: !enabled }),
});
const data = await res.json();
setEnabled(!!data.enabled);
setError(null);
} catch (err: any) {
setError(err?.message ?? 'Failed to toggle');
} finally {
setBusy(false);
}
}
function showRendered() {
setView('rendered');
if (capture) setPinned(capture);
@@ -273,28 +249,11 @@ export default function AutoBuyer() {
<div className="max-w-7xl mx-auto">
<h1 className="text-2xl font-bold text-slate-900 mb-6">AutoBuyer</h1>
{/* ── Capture switch and daemon status ── */}
{/* ── Daemon status ──
There is no on/off switch. Page capture follows whichever firm
tab you are looking at, and the AutoBuyer is ready whenever the
daemon below is up — so that row is the whole of the state. */}
<div className="bg-white border border-slate-200 rounded-xl shadow-sm mb-6">
<div className="flex items-center justify-between px-4 py-3 border-b border-slate-100">
<div>
<p className="text-sm font-medium text-slate-800">Page capture</p>
<p className="text-xs text-slate-400 mt-0.5">
While on, the AutoFirmer Capture extension posts the target tab&apos;s HTML here every few seconds
</p>
</div>
<button
onClick={toggle}
disabled={busy}
className={`text-sm px-4 py-1.5 rounded-lg font-medium transition-colors disabled:opacity-50 ${
enabled
? 'bg-green-500 hover:bg-green-600 text-white'
: 'bg-slate-200 hover:bg-slate-300 text-slate-700'
}`}
>
{busy ? '…' : enabled ? 'ON' : 'OFF'}
</button>
</div>
<div className="flex items-center justify-between px-4 py-3">
<div>
<p className="text-sm font-medium text-slate-800">Autoclicker daemon</p>
@@ -411,11 +370,10 @@ export default function AutoBuyer() {
))}
<button
onClick={() => startRun(a)}
disabled={!enabled || busyRun || activeRun !== null || !runner?.online || !!runner?.stale}
disabled={busyRun || activeRun !== null || !runner?.online || !!runner?.stale}
title={
!enabled ? 'AutoBuyer is switched off'
: !runner?.online ? 'The runner is not running'
: runner?.stale ? 'The runner is out of date — restart it'
!runner?.online ? 'The runner is not running'
: runner?.stale ? 'The runner is out of date — restart it'
: activeRun !== null ? 'A run is already in progress'
: undefined
}
@@ -484,13 +442,9 @@ export default function AutoBuyer() {
Latest capture
</h2>
{!enabled ? (
{!capture ? (
<div className="bg-white border border-slate-200 rounded-xl shadow-sm p-8 text-center text-slate-400">
Capture is off
</div>
) : !capture ? (
<div className="bg-white border border-slate-200 rounded-xl shadow-sm p-8 text-center text-slate-400">
Waiting for the extension… open a page in Chrome with the extension installed
Waiting for the extension… switch to a firm tab in the Chrome window that has it installed
</div>
) : (
<div className="bg-white border border-slate-200 rounded-xl shadow-sm overflow-hidden">