Add agent automations: 'hey superbrain' NL-compiled watch-and-act tasks
release gate / check (push) Failing after 6m37s

The first real-agent slice (PLAN_PRICING_TIERS step 5, partial): describe
an automation in plain language — 'when the round trip on <url> drops
below $400, email david@…' — and Superbrain compiles it into a task the
user reviews and confirms before anything is stored.

Trust model (the point of the whole design): the LLM only ever PROPOSES.
Compile output and hand-built specs pass the same server-side
agent.ValidateSpec on every write AND on every engine load (a spec that
stops validating is paused, never executed). Actions are a closed set —
notify an owned channel, email one recipient, save one bookmark — with no
destructive or cross-user capability. Fetched page content is untrusted:
delimited in the extraction prompt, schema-checked reply ({found,value,
text,summary}), and no action can be chosen or retargeted by page text.
Multi-step requests (flights AND hotels bundled) are explicitly refused by
the compiler until chaining exists.

internal/ai: OpenAI-compatible gateway (OpenRouter default via AI_API_KEY/
AI_MODEL/AI_BASE_URL; any compatible endpoint works — house Core gateway or
Ollama later). Netguard-dialed, outbound-budgeted, balanced-brace JSON
extraction, provider bodies never echoed wholesale (they can reflect keys).

internal/agent: url_watch (scheduled fetch + one extracted fact + numeric/
text comparison) and signal (new mailbox signals, keyword filter)
conditions; poll floor 15min, once-semantics, per-task email cap 5,
per-owner daily email cap 20, global advisory tick lease, bounded run
history (pruned tail + age horizon). Engine loop joins signals/notify in
main's shutdown contract.

Schema: AgentTask + AgentRun (migration 014, converge-verified).
Entitlements: AITasks cap per plan (free 2 / standard 10 / premium 50 /
core+selfhosted unlimited) + ai_tasks override key — stored-task count is
plan data, never TIER checks.

API: /api/agent/compile (rate-limited, 422 surfaces the model's refusal,
503 when AI unconfigured), task CRUD with the version contract, manual
/run, bounded /runs history. Web: Settings -> Automations with the
composer, human-readable proposal + raw-spec review, channel picker for
notify actions, task list with Run now, and the runs strip (SafeTime for
hydration-safe timestamps).

Tests: loopback fake OpenAI-compatible server + watch target + the SMTP
fake — compile success/refusal/invalid-spec, create-time validation
(javascript: URLs rejected), version contract, url_watch fire with
once-completion, signal fire + no-refire without new signals, plan cap via
ai_tasks override, 503 without a key. Full suite green (-race); converge
green; web lint/SSR-eslint/build clean.

Docs: API.md agent section, RUNNING.md, .env.example (key stays in .env
only), compose passthrough.
This commit is contained in:
Andrew S Erwin
2026-10-27 22:54:25 -05:00
parent 2f89719f0a
commit 2037a04817
17 changed files with 1964 additions and 4 deletions
+10
View File
@@ -252,6 +252,16 @@ The core app works without any external services.
synced contact with a bookmark.
- **Browser alerts:** Allow notifications when prompted. Alert checks run
while the app is open in your browser.
- **AI automations ("hey superbrain"):** in **Settings → Automations**,
describe an automation in plain language; Superbrain compiles it into a
task you review before it is saved. Tasks can watch a public web page on
a schedule (one extracted fact per check, e.g. a price threshold) or
react to new mailbox signals, then notify a channel, email a recipient,
or save a bookmark. Set `AI_API_KEY` (OpenRouter by default; any
OpenAI-compatible gateway via `AI_BASE_URL`/`AI_MODEL`) — without it,
compilation and page extraction are unavailable but signal tasks still
run. The model only ever proposes validated specs; actions are fixed
primitives with fire caps, and every fetch goes through netguard.
- **Notifications:** In **Settings → Notifications**, add a delivery channel
(email, Slack webhook, Matrix room, Telegram bot) and rules that fire on
new mailbox signals or due bookmarks. Channel availability follows the