feat: a "Run now" button for the memory lints — one pass, for whoever asked
Nightly Build / build (push) Successful in 7m33s
Nightly Build / build (push) Successful in 7m33s
The two memory lints run weekly, which is right for maintenance and wrong for the moment somebody has just reorganised their notes and wants to know what the lint makes of them. Each agent's tab now carries a button that starts one pass immediately, for the caller. It runs as the caller — their pool, their sessions, their hub — so the report lands with the person who asked. The shared lint is the interesting case: its scheduled pass runs as the admin because the shared store belongs to nobody, but a member pressing the button reads the same store and gets the report themselves, which is coherent with shared memory being readable by every member anyway. Two settings are treated differently on purpose. Due-ness is skipped, exactly as manual /compact skips the compactor's token threshold: the interval answers *when*, and a human asking is a good enough answer to that. The Enabled switch is honoured: it answers *whether*, and that one is the admin's. The conversation review gets no button (AgentScope::PerSubject): it is about somebody else and picks its own subjects, so "run it for me" has no meaning. The frontend reads that from the agent's scope, not from a list of ids. A second starter breaks an invariant the scheduler used to hold for free. system_agent_runs::start sweeps any leftover `running` row of the same agent to `failed` before inserting, which was safe only because one sequential loop was the only thing that ever started a pass; a manual run overlapping a scheduled one would have marked a healthy run as interrupted and duplicated its work. So the agent list moves out of the scheduler and onto Skald as SystemAgents, which holds the registry plus an in-flight guard both paths claim through — keyed on what the pass is *about*, so an instance-wide agent is one slot no matter who runs it, and a per-subject review is keyed on the subject rather than on the supervisor lending the runtime. has_work is answered synchronously, before anything is spawned: it leaves no run row, so without that the button would say "started" over a log that never gains a row. Everything after it is spawned — a pass is an LLM turn, and no HTTP request should be held open for one. The run row exists before the browser is answered, so the log itself is the progress surface; the page polls it quietly until the pass leaves `running`.
This commit is contained in:
@@ -9,6 +9,15 @@ const PER_PAGE = 20;
|
||||
/** The overview tab: every agent's runs, interleaved. */
|
||||
const ALL_TAB = '__all__';
|
||||
|
||||
/**
|
||||
* How a manually started pass is followed: the run row appears immediately (the
|
||||
* server opens it before the work), so the log itself is the progress bar and
|
||||
* nothing else has to be invented. Refreshing quietly — without the table's
|
||||
* loading state — is what keeps that from flickering every few seconds.
|
||||
*/
|
||||
const POLL_MS = 4000;
|
||||
const POLL_MAX_MIN = 15;
|
||||
|
||||
function formatDate(iso) {
|
||||
if (!iso) return '—';
|
||||
return new Date(iso).toLocaleString(undefined, {
|
||||
@@ -59,6 +68,8 @@ export class SystemAgentsPage extends LightElement {
|
||||
_page: { state: true },
|
||||
_loading: { state: true },
|
||||
_error: { state: true },
|
||||
_running: { state: true },
|
||||
_runMsg: { state: true },
|
||||
};
|
||||
|
||||
constructor() {
|
||||
@@ -72,6 +83,11 @@ export class SystemAgentsPage extends LightElement {
|
||||
this._page = 1;
|
||||
this._loading = false;
|
||||
this._error = null;
|
||||
/** The agent whose manual run we are waiting on, if any. */
|
||||
this._running = null;
|
||||
/** `{ agent, text, error }` — the answer to the last press. */
|
||||
this._runMsg = null;
|
||||
this._poll = null;
|
||||
this._form = new ConfigFormController(() => this.requestUpdate());
|
||||
}
|
||||
|
||||
@@ -83,11 +99,15 @@ export class SystemAgentsPage extends LightElement {
|
||||
this._open = e.detail.page === PAGE_ID;
|
||||
this.style.display = this._open ? 'flex' : 'none';
|
||||
if (this._open) this._loadAll();
|
||||
// Navigating away stops the polling; the pass keeps running server-side
|
||||
// and its row is waiting on the next visit.
|
||||
else this._stopPolling();
|
||||
});
|
||||
}
|
||||
|
||||
disconnectedCallback() {
|
||||
window.removeEventListener('locale-changed', this.__onLocaleChanged);
|
||||
this._stopPolling();
|
||||
super.disconnectedCallback();
|
||||
}
|
||||
|
||||
@@ -113,8 +133,9 @@ export class SystemAgentsPage extends LightElement {
|
||||
}
|
||||
}
|
||||
|
||||
async _fetch(page) {
|
||||
this._loading = true;
|
||||
/** `quiet` skips the loading state, so a poll does not blank the table. */
|
||||
async _fetch(page, quiet = false) {
|
||||
if (!quiet) this._loading = true;
|
||||
this._error = null;
|
||||
try {
|
||||
const params = new URLSearchParams({ page, per_page: PER_PAGE });
|
||||
@@ -134,11 +155,59 @@ export class SystemAgentsPage extends LightElement {
|
||||
|
||||
_selectTab(id) {
|
||||
if (this._tab === id) return;
|
||||
this._tab = id;
|
||||
this._page = 1;
|
||||
this._tab = id;
|
||||
this._page = 1;
|
||||
this._runMsg = null;
|
||||
this._fetch(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Start one pass now, for me.
|
||||
*
|
||||
* The button asks and stops there: the server answers as soon as the pass is
|
||||
* *scheduled*, because a pass is an LLM turn and nothing good comes of holding
|
||||
* a request open for it. "Nothing to do" is a real answer and arrives straight
|
||||
* away — it leaves no run row, so without it the table would simply never
|
||||
* change and the press would look lost.
|
||||
*/
|
||||
async _runNow(agent) {
|
||||
if (this._running) return;
|
||||
this._running = agent.id;
|
||||
this._runMsg = null;
|
||||
try {
|
||||
const res = await fetch(`/api/system-agents/${encodeURIComponent(agent.id)}/run`,
|
||||
{ method: 'POST' });
|
||||
if (!res.ok) throw new Error((await res.text()) || `HTTP ${res.status}`);
|
||||
const data = await res.json();
|
||||
if (data.status === 'nothing_to_do') {
|
||||
this._runMsg = { agent: agent.id, text: t('system_agents.run.nothing') };
|
||||
} else {
|
||||
this._runMsg = { agent: agent.id, text: t('system_agents.run.started') };
|
||||
await this._fetch(1, true);
|
||||
this._startPolling();
|
||||
}
|
||||
} catch (e) {
|
||||
this._runMsg = { agent: agent.id, text: e.message, error: true };
|
||||
} finally {
|
||||
this._running = null;
|
||||
}
|
||||
}
|
||||
|
||||
/** Refresh the log until the pass leaves `running`, then stop. */
|
||||
_startPolling() {
|
||||
this._stopPolling();
|
||||
const until = Date.now() + POLL_MAX_MIN * 60_000;
|
||||
this._poll = setInterval(async () => {
|
||||
await this._fetch(this._page, true);
|
||||
const live = this._items.some(r => r.status === 'running');
|
||||
if (!live || Date.now() > until) this._stopPolling();
|
||||
}, POLL_MS);
|
||||
}
|
||||
|
||||
_stopPolling() {
|
||||
if (this._poll) { clearInterval(this._poll); this._poll = null; }
|
||||
}
|
||||
|
||||
_openSession(id) {
|
||||
if (id != null) window.location.hash = `session/${id}`;
|
||||
}
|
||||
@@ -185,15 +254,43 @@ export class SystemAgentsPage extends LightElement {
|
||||
</div>`;
|
||||
}
|
||||
|
||||
/** The selected agent's description, plus its settings when the caller is an admin. */
|
||||
/**
|
||||
* The selected agent's description and its **Run now** button, plus its
|
||||
* settings when the caller is an admin.
|
||||
*
|
||||
* The button sits with the description rather than in the page header because
|
||||
* it acts on *this* agent, not on the page: the header's Refresh reloads
|
||||
* whatever is on screen, and a "Run" next to it would read as running all of
|
||||
* them. Agents that work on somebody else (the conversation review) have no
|
||||
* "for me" to run and say so with `can_run_now: false`.
|
||||
*/
|
||||
_renderAgentPanel() {
|
||||
const agent = this._currentAgent;
|
||||
if (!agent) return nothing;
|
||||
const label = this._agentLabel(agent);
|
||||
const label = this._agentLabel(agent);
|
||||
const busy = this._running === agent.id;
|
||||
const msg = this._runMsg?.agent === agent.id ? this._runMsg : null;
|
||||
|
||||
return html`
|
||||
<div class="sa-agent-panel">
|
||||
<p class="sa-agent-desc">${label.description}</p>
|
||||
${agent.can_run_now ? html`
|
||||
<div class="sa-agent-actions">
|
||||
<button class="btn btn-sm btn-outline-primary"
|
||||
?disabled=${busy}
|
||||
@click=${() => this._runNow(agent)}>
|
||||
${busy
|
||||
? html`<span class="spinner-border spinner-border-sm" role="status"></span>`
|
||||
: html`<i class="bi bi-play-fill"></i>`}
|
||||
${t('system_agents.run.now')}
|
||||
</button>
|
||||
<small class="sa-run-hint">${t('system_agents.run.hint')}</small>
|
||||
${msg ? html`
|
||||
<span class="sa-run-msg ${msg.error ? 'sa-run-msg--error' : ''}">
|
||||
<i class="bi ${msg.error ? 'bi-exclamation-circle' : 'bi-info-circle'}"></i>
|
||||
${msg.text}
|
||||
</span>` : nothing}
|
||||
</div>` : nothing}
|
||||
${this._canCfg && agent.config ? html`
|
||||
<div class="config-set sa-agent-config">
|
||||
<div class="config-set-header">
|
||||
|
||||
@@ -61,6 +61,31 @@
|
||||
}
|
||||
.sa-agent-config { margin-bottom: 0; }
|
||||
|
||||
/* Run now: the button, its one-line explanation, and the answer to the press —
|
||||
on one row, wrapping on a narrow viewport rather than pushing the table down. */
|
||||
.sa-agent-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.6rem;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
.sa-run-hint {
|
||||
color: var(--bs-secondary-color);
|
||||
font-size: 0.78rem;
|
||||
}
|
||||
.sa-run-msg {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.35rem;
|
||||
font-size: 0.82rem;
|
||||
color: var(--bs-body-color);
|
||||
background: var(--bs-tertiary-bg);
|
||||
border-radius: 0.4rem;
|
||||
padding: 0.2rem 0.55rem;
|
||||
}
|
||||
.sa-run-msg--error { color: var(--bs-danger); }
|
||||
|
||||
/* ── Run table ─────────────────────────────────────────────────────────────── */
|
||||
|
||||
.sa-table-wrap {
|
||||
|
||||
@@ -977,6 +977,11 @@ export default {
|
||||
'system_agents.tab.all': 'All',
|
||||
'system_agents.settings': 'Settings',
|
||||
|
||||
'system_agents.run.now': 'Run now',
|
||||
'system_agents.run.hint': 'Runs one pass for you, straight away, without waiting for the schedule.',
|
||||
'system_agents.run.started': 'Started — it appears in the log below and reports when it is done.',
|
||||
'system_agents.run.nothing': 'Nothing to look at right now, so no run was started.',
|
||||
|
||||
'system_agents.agent.event-triage.name': 'Event triage',
|
||||
'system_agents.agent.event-triage.desc': 'Reads the events your connectors receive — new mail, calendar changes, incoming messages — decides which of them are worth your attention, and notifies you about those. It runs for one person at a time and reads only that person\'s events.',
|
||||
'system_agents.agent.memory-lint-private.name': 'Private memory lint',
|
||||
|
||||
@@ -967,6 +967,11 @@ export default {
|
||||
'system_agents.tab.all': 'Tous',
|
||||
'system_agents.settings': 'Paramètres',
|
||||
|
||||
'system_agents.run.now': 'Exécuter maintenant',
|
||||
'system_agents.run.hint': 'Lance immédiatement une passe pour vous, sans attendre la planification.',
|
||||
'system_agents.run.started': 'Lancé — l\'exécution apparaît dans le journal ci-dessous et vous prévient une fois terminée.',
|
||||
'system_agents.run.nothing': 'Rien à examiner pour le moment, aucune exécution n\'a donc été lancée.',
|
||||
|
||||
'system_agents.agent.event-triage.name': 'Tri des événements',
|
||||
'system_agents.agent.event-triage.desc': 'Lit les événements reçus par vos connecteurs — nouveaux e-mails, changements d\'agenda, messages entrants — décide lesquels méritent votre attention et ne vous signale que ceux-là. Il s\'exécute pour une personne à la fois et ne lit que les événements de cette personne.',
|
||||
'system_agents.agent.memory-lint-private.name': 'Entretien de la mémoire privée',
|
||||
|
||||
@@ -967,6 +967,11 @@ export default {
|
||||
'system_agents.tab.all': 'Tutti',
|
||||
'system_agents.settings': 'Impostazioni',
|
||||
|
||||
'system_agents.run.now': 'Esegui ora',
|
||||
'system_agents.run.hint': 'Esegue subito una passata per te, senza aspettare la pianificazione.',
|
||||
'system_agents.run.started': 'Avviato — compare nel registro qui sotto e ti avvisa quando ha finito.',
|
||||
'system_agents.run.nothing': 'Al momento non c\'è nulla da esaminare, quindi non è stata avviata nessuna esecuzione.',
|
||||
|
||||
'system_agents.agent.event-triage.name': 'Triage eventi',
|
||||
'system_agents.agent.event-triage.desc': 'Legge gli eventi che arrivano dai tuoi connettori — nuove email, modifiche al calendario, messaggi in arrivo — decide quali meritano la tua attenzione e ti avvisa solo di quelli. Viene eseguito per una persona alla volta e legge solo gli eventi di quella persona.',
|
||||
'system_agents.agent.memory-lint-private.name': 'Manutenzione memoria privata',
|
||||
|
||||
Reference in New Issue
Block a user