system agents: generalise the scheduler and add the two memory lints
Nightly Build / build (push) Successful in 7m14s
Nightly Build / build (push) Successful in 7m14s
Memory is kept as a maintained wiki, and a wiki nobody prunes rots. This adds
the scheduled maintenance pass, and generalises the machinery TIC had grown so
that a background agent is a trait impl rather than a loop of its own.
Two lint agents, not one. The private pass runs per user over `user-memory/`
and reports to them; the shared pass runs once over `shared-memory/`, where the
interesting defect is different — a note failing the table rule, i.e. private
business written where every member can read it. It names the note and the
category without repeating the content, since restating it spreads the very
thing being flagged. Both share `agents/common/memory-lint.md`.
Both are read-only, and that is enforced twice: the prompt says report-never-
repair, and `shared-memory/*` writes are already `@fs_write require`, so an
agent that tried to fix something would raise an approval card from an
unattended pass, which is auto-denied. Read-only is the only design that works
here, not merely the safe one.
One scheduler for cadences three orders of magnitude apart. TIC runs every few
minutes, a lint weekly — the case that tempts a second loop. It stays one
because the wake-up decides nothing: `base_tick` picks only how often to look,
and whether an agent runs for a user is `is_due` against persisted state.
Due-ness moves out of the run log into a new owner table, `system_agent_state`.
The two answer different questions: the run log skips idle ticks so it stays a
history rather than a heartbeat, while scheduling needs every attempt. Reading
due-ness off the log would re-run an idle agent on every tick and never bring a
weekly one due once its last productive run aged out. Persisting it is also
what makes a long interval survive a restart — an in-memory deadline is fine at
TIC's scale, but a weekly agent on a box rebooted every few days would have it
re-armed before it ever fired.
The shared store belongs to nobody, so `AgentScope::Instance` runs that pass as
the first unlocked admin. An ownerless run would write its trace into system.db,
which the runs endpoint shows to nobody by design, and its notify() would have
no recipient; attributing it to a user keeps the whole per-user surface working
unchanged.
Settings move to where the run log is. `ConfigSet` gains `owner`, so placement
is data on the set rather than a page that knows set names; the System agents
page grows one tab per agent holding its description, its settings (admin only)
and its runs — "why did this do nothing last night?" is half a schedule
question and half a log question. The form is shared with the Config page, and
writes still go through PUT /api/config/{key}.
Fixes an authorization gap found on the way: neither /api/config handler took
the caller into account, so any authenticated session could read and write
instance-wide config. The sidebar hiding the page is presentation, not access
control. Both are now admin-gated.
This commit is contained in:
+19
-165
@@ -1,32 +1,23 @@
|
||||
import { html, nothing } from 'lit';
|
||||
import { LightElement } from '../lib/base.js';
|
||||
import { t } from '../lib/i18n.js';
|
||||
import { ConfigFormController, maybeT, propKeyId } from './shared/config-form.js';
|
||||
|
||||
function _maybeT(key, fallback) {
|
||||
const v = t(key);
|
||||
return v !== key ? v : fallback;
|
||||
}
|
||||
|
||||
// Sets whose labels this page ships translations for. A set with no slug falls
|
||||
// back to the backend's own English text, which is also what happens to a newly
|
||||
// added one until it is translated.
|
||||
function _configSetSlug(name) {
|
||||
const slugs = {
|
||||
'Interface': 'interface',
|
||||
'TIC Agent': 'tic_agent',
|
||||
'Interface': 'interface',
|
||||
'Compaction': 'compaction',
|
||||
};
|
||||
return slugs[name] ?? null;
|
||||
}
|
||||
|
||||
function _propKeyId(propKey) {
|
||||
return propKey.replace(/\./g, '__');
|
||||
}
|
||||
|
||||
export class ConfigPage extends LightElement {
|
||||
static properties = {
|
||||
_open: { state: true },
|
||||
_properties: { state: true },
|
||||
_values: { state: true }, // { [key]: string }
|
||||
_saving: { state: true }, // Set<key>
|
||||
_saved: { state: true }, // Set<key> (brief flash)
|
||||
_error: { state: true },
|
||||
_debugMode: { state: true },
|
||||
_debugLoading: { state: true },
|
||||
@@ -36,12 +27,12 @@ export class ConfigPage extends LightElement {
|
||||
super();
|
||||
this._open = false;
|
||||
this._properties = [];
|
||||
this._values = {};
|
||||
this._saving = new Set();
|
||||
this._saved = new Set();
|
||||
this._error = null;
|
||||
this._debugMode = false;
|
||||
this._debugLoading = true;
|
||||
// Values, in-flight saves and the saved-flash live in the shared controller,
|
||||
// which also owns the write path (see `shared/config-form.js`).
|
||||
this._form = new ConfigFormController(() => this.requestUpdate());
|
||||
}
|
||||
|
||||
connectedCallback() {
|
||||
@@ -96,166 +87,29 @@ export class ConfigPage extends LightElement {
|
||||
if (!res.ok) throw new Error(await res.text());
|
||||
const data = await res.json();
|
||||
this._properties = data.sets ?? [];
|
||||
const vals = {};
|
||||
for (const s of this._properties)
|
||||
for (const p of s.properties) vals[p.key] = p.value ?? '';
|
||||
this._values = vals;
|
||||
this._form.seedFromSets(this._properties);
|
||||
} catch (e) {
|
||||
this._error = e.message;
|
||||
}
|
||||
}
|
||||
|
||||
_setValue(key, val) {
|
||||
this._values = { ...this._values, [key]: val };
|
||||
}
|
||||
|
||||
async _save(prop) {
|
||||
const key = prop.key;
|
||||
const value = this._values[key] ?? '';
|
||||
|
||||
this._saving = new Set([...this._saving, key]);
|
||||
this.requestUpdate();
|
||||
|
||||
try {
|
||||
const res = await fetch(`/api/config/${encodeURIComponent(key)}`, {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ value }),
|
||||
});
|
||||
if (!res.ok) throw new Error(await res.text());
|
||||
|
||||
this._saved = new Set([...this._saved, key]);
|
||||
setTimeout(() => {
|
||||
this._saved = new Set([...this._saved].filter(k => k !== key));
|
||||
}, 1500);
|
||||
} catch (e) {
|
||||
alert(t('config.error_save', { name: prop.name, msg: e.message }));
|
||||
} finally {
|
||||
this._saving = new Set([...this._saving].filter(k => k !== key));
|
||||
}
|
||||
}
|
||||
|
||||
_renderInput(prop) {
|
||||
const val = this._values[prop.key] ?? '';
|
||||
|
||||
if (prop.property_type === 'bool') {
|
||||
const effective = val !== '' ? val : (prop.default_value ?? 'true');
|
||||
const checked = effective !== 'false';
|
||||
return html`
|
||||
<div class="form-check form-switch config-bool-switch">
|
||||
<input class="form-check-input" type="checkbox" role="switch"
|
||||
id="cfg-${prop.key}"
|
||||
.checked=${checked}
|
||||
@change=${e => { this._setValue(prop.key, e.target.checked ? 'true' : 'false'); this._save(prop); }} />
|
||||
<label class="form-check-label" for="cfg-${prop.key}">
|
||||
${checked ? t('config.enabled') : t('config.disabled')}
|
||||
</label>
|
||||
</div>`;
|
||||
}
|
||||
|
||||
if (prop.property_type === 'int') {
|
||||
return html`
|
||||
<input type="number" step="1" min="1"
|
||||
class="form-control form-control-sm config-input"
|
||||
.value=${val}
|
||||
placeholder=${prop.default_value ?? ''}
|
||||
@input=${e => this._setValue(prop.key, e.target.value)} />`;
|
||||
}
|
||||
|
||||
// Dropdown-style property types. The backend ships the allowed values in
|
||||
// `prop.options` (a list of {id, name}); we only decide how to frame them.
|
||||
// Adding a new custom type from a config section? Give it a `property_type`
|
||||
// on the backend, attach its `options`, and add a branch like these — a
|
||||
// free-text box becomes a proper picker for the price of a few lines.
|
||||
if (prop.property_type === 'security_group') {
|
||||
// Nullable: the empty choice means "fall back to the instance default".
|
||||
const groups = prop.options ?? [];
|
||||
return html`
|
||||
<select class="form-select form-select-sm config-input"
|
||||
.value=${val}
|
||||
@change=${e => this._setValue(prop.key, e.target.value)}>
|
||||
<option value="">— default —</option>
|
||||
${groups.map(g => html`
|
||||
<option value=${g.id} ?selected=${val === g.id}>${g.name}</option>`)}
|
||||
</select>`;
|
||||
}
|
||||
|
||||
if (prop.property_type === 'locale') {
|
||||
// Interface languages the instance supports; labels are native endonyms.
|
||||
// Always a concrete pick (no empty option) — falls back to default_value.
|
||||
const locales = prop.options ?? [];
|
||||
const current = val || prop.default_value || 'en';
|
||||
return html`
|
||||
<select class="form-select form-select-sm config-input"
|
||||
.value=${current}
|
||||
@change=${e => { this._setValue(prop.key, e.target.value); this._save(prop); }}>
|
||||
${locales.map(l => html`
|
||||
<option value=${l.id} ?selected=${current === l.id}>${l.name}</option>`)}
|
||||
</select>`;
|
||||
}
|
||||
|
||||
if (prop.property_type === 'llm_model') {
|
||||
// Configured LLM models, by name. Nullable: the empty choice means
|
||||
// "auto-select" (the backend's own resolution order applies).
|
||||
const models = prop.options ?? [];
|
||||
return html`
|
||||
<select class="form-select form-select-sm config-input"
|
||||
.value=${val}
|
||||
@change=${e => this._setValue(prop.key, e.target.value)}>
|
||||
<option value="">— ${t('config.llm_model.auto')} —</option>
|
||||
${models.map(m => html`
|
||||
<option value=${m.id} ?selected=${val === m.id}>${m.name}</option>`)}
|
||||
</select>`;
|
||||
}
|
||||
|
||||
return html`
|
||||
<input type="text"
|
||||
class="form-control form-control-sm config-input"
|
||||
.value=${val}
|
||||
placeholder=${prop.default_value ?? ''}
|
||||
@input=${e => this._setValue(prop.key, e.target.value)} />`;
|
||||
}
|
||||
|
||||
_renderSet(set) {
|
||||
const slug = _configSetSlug(set.name);
|
||||
const sName = slug ? _maybeT(`config.set.${slug}.name`, set.name) : set.name;
|
||||
const sDesc = slug ? _maybeT(`config.set.${slug}.desc`, set.description) : set.description;
|
||||
const slug = _configSetSlug(set.name);
|
||||
const sName = slug ? maybeT(`config.set.${slug}.name`, set.name) : set.name;
|
||||
const sDesc = slug ? maybeT(`config.set.${slug}.desc`, set.description) : set.description;
|
||||
return html`
|
||||
<div class="config-set">
|
||||
<div class="config-set-header">
|
||||
<div class="config-set-name">${sName}</div>
|
||||
<div class="config-set-desc">${sDesc}</div>
|
||||
</div>
|
||||
<div class="config-rows">
|
||||
${set.properties.map(p => this._renderRow(p))}
|
||||
</div>
|
||||
</div>`;
|
||||
}
|
||||
|
||||
_renderRow(prop) {
|
||||
const saving = this._saving.has(prop.key);
|
||||
const saved = this._saved.has(prop.key);
|
||||
const pk = _propKeyId(prop.key);
|
||||
const pName = _maybeT(`config.prop.${pk}.name`, prop.name);
|
||||
const pDesc = _maybeT(`config.prop.${pk}.desc`, prop.description);
|
||||
|
||||
return html`
|
||||
<div class="config-row">
|
||||
<div class="config-row-meta">
|
||||
<div class="config-row-name">${pName}</div>
|
||||
<div class="config-row-desc">${pDesc}</div>
|
||||
</div>
|
||||
<div class="config-row-control">
|
||||
${this._renderInput(prop)}
|
||||
${!['bool', 'locale'].includes(prop.property_type) ? html`
|
||||
<button class="btn btn-sm ${saved ? 'btn-success' : 'btn-primary'} config-save-btn"
|
||||
?disabled=${saving}
|
||||
@click=${() => this._save(prop)}>
|
||||
${saving
|
||||
? html`<span class="spinner-border spinner-border-sm"></span>`
|
||||
: saved ? t('common.saved') : t('common.save')}
|
||||
</button>` : nothing}
|
||||
</div>
|
||||
${this._form.renderRows(set.properties, p => {
|
||||
const pk = propKeyId(p.key);
|
||||
return {
|
||||
name: maybeT(`config.prop.${pk}.name`, p.name),
|
||||
description: maybeT(`config.prop.${pk}.desc`, p.description),
|
||||
};
|
||||
})}
|
||||
</div>`;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user