feat(plugins): persist enable-intent across restarts + redesign admin page

The deactivation-on-deploy bug: `status` conflated the admin's ON/OFF intent with
runtime health, so a boot crash flipped status to 'error' and the plugin never
rebooted after the next deploy. Migration 156 adds an `enabled` flag (admin
intent) separate from `status` (runtime health); boot now retries every enabled
plugin regardless of last status, and a crash no longer erases the intent.

Admin → Plugins redesign:
- ON/OFF is a ToggleSwitch bound to `enabled`; runtime health shows separately as
  a coloured status dot, with the last error inline when it crashed.
- "Update → vX" badge when the registry has a newer version (one click updates
  and reactivates).
- Reviewed/unreviewed trust badges, cleaner cards, nicer empty state, registry
  browser marks already-installed plugins. i18n across all locales.
This commit is contained in:
mauriceboe
2026-07-03 19:19:30 +02:00
parent 1a7f7a9340
commit 529c17baf4
28 changed files with 424 additions and 106 deletions
@@ -52,8 +52,11 @@ export class PluginRuntimeService implements OnModuleInit, OnModuleDestroy {
} catch {
/* discovery must never block boot */
}
const active = db.prepare("SELECT id FROM plugins WHERE status = 'active'").all() as Array<{ id: string }>;
for (const { id } of active) {
// Boot everything the admin left ENABLED, regardless of the last runtime
// status — a crash or a bad deploy set status='error' but must not silently
// keep the plugin down forever.
const enabled = db.prepare('SELECT id FROM plugins WHERE enabled = 1').all() as Array<{ id: string }>;
for (const { id } of enabled) {
this.activate(id).catch(() => {
/* status is persisted as error by the supervisor hook */
});
@@ -79,7 +82,8 @@ export class PluginRuntimeService implements OnModuleInit, OnModuleDestroy {
// Activating IS the consent gate: grant the plugin's DECLARED permissions
// (the admin reviewed them on the consent screen), persist, then spawn.
const declared = parseArray(row.permissions).filter(isKnownPermission);
db.prepare('UPDATE plugins SET granted_permissions = ? WHERE id = ?').run(JSON.stringify(declared), id);
// Mark it enabled (admin intent) so it reboots after restarts/crashes.
db.prepare('UPDATE plugins SET granted_permissions = ?, enabled = 1 WHERE id = ?').run(JSON.stringify(declared), id);
const config = decryptConfig(parseObject(row.config));
const egress = declared.filter((p) => p.startsWith('http:outbound:')).map((p) => p.slice('http:outbound:'.length));
await this.supervisor.activate(id, new Set(declared), config, egress);
@@ -88,7 +92,7 @@ export class PluginRuntimeService implements OnModuleInit, OnModuleDestroy {
async deactivate(id: string): Promise<void> {
await this.supervisor.disable(id);
closePluginDataDb(id);
db.prepare("UPDATE plugins SET status = 'inactive', updated_at = CURRENT_TIMESTAMP WHERE id = ?").run(id);
db.prepare("UPDATE plugins SET status = 'inactive', enabled = 0, updated_at = CURRENT_TIMESTAMP WHERE id = ?").run(id);
}
/** Stop the plugin, remove its code, and optionally delete all its data. */