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
+15 -1
View File
@@ -53,6 +53,10 @@ type Limits struct {
// AIMode: byo (bring your own key) | credits (built-in, metered) |
// core (house Core AI settings).
AIMode string
// AITasks caps concurrently stored agent automations per tenant
// (-1 unlimited). Evaluation rate limits live in the engine; this is
// the storage-side plan differentiator.
AITasks int64
}
// catalog is the shipped plan matrix (PLAN_PRICING_TIERS.md). Editing a
@@ -66,6 +70,7 @@ var catalog = map[Plan]Limits{
NotificationChannels: []string{"email"},
Connectors: []string{"url", "file", "carddav"},
AIMode: "byo",
AITasks: 2,
},
PlanStandard: {
StorageBytes: 25 * 1024 * 1024 * 1024,
@@ -74,6 +79,7 @@ var catalog = map[Plan]Limits{
NotificationChannels: []string{"email", "slack", "matrix"},
Connectors: []string{"url", "file", "carddav", "google", "office365", "nextcloud", "webdav", "caldav", "gmail"},
AIMode: "byo",
AITasks: 10,
},
PlanPremium: {
StorageBytes: 100 * 1024 * 1024 * 1024,
@@ -82,6 +88,7 @@ var catalog = map[Plan]Limits{
NotificationChannels: []string{"email", "slack", "matrix", "telegram"},
Connectors: []string{"url", "file", "carddav", "google", "office365", "nextcloud", "webdav", "caldav", "gmail", "oidc"},
AIMode: "credits",
AITasks: 50,
},
PlanCore: {
StorageBytes: Unlimited, // storage on Core
@@ -90,6 +97,7 @@ var catalog = map[Plan]Limits{
NotificationChannels: []string{"email", "slack", "matrix", "telegram", "talk"},
Connectors: []string{"url", "file", "carddav", "google", "office365", "nextcloud", "webdav", "caldav", "gmail", "oidc", "mcp-core"},
AIMode: "core",
AITasks: Unlimited,
},
PlanSelfHosted: {
StorageBytes: Unlimited, // limits are the operator's hardware
@@ -98,6 +106,7 @@ var catalog = map[Plan]Limits{
NotificationChannels: []string{"email", "slack", "matrix", "telegram"},
Connectors: []string{"url", "file", "carddav", "google", "office365", "nextcloud", "webdav", "caldav", "gmail", "oidc"},
AIMode: "byo",
AITasks: Unlimited,
},
}
@@ -152,6 +161,7 @@ const (
KeyNotificationChannels = "notification_channels"
KeyConnectors = "connectors"
KeyAIMode = "ai_mode"
KeyAITasks = "ai_tasks"
)
// ValidOverrideKey reports whether k is a known TenantEntitlement key.
@@ -159,7 +169,7 @@ const (
// READING ignores unknown keys so rows from a newer version stay harmless.
func ValidOverrideKey(k string) bool {
switch k {
case KeyStorageBytes, KeyBrainLinks, KeySeats, KeyNotificationChannels, KeyConnectors, KeyAIMode:
case KeyStorageBytes, KeyBrainLinks, KeySeats, KeyNotificationChannels, KeyConnectors, KeyAIMode, KeyAITasks:
return true
}
return false
@@ -185,6 +195,10 @@ func ApplyOverrides(l Limits, overrides map[string]string) Limits {
if n, err := strconv.ParseInt(v, 10, 64); err == nil && (n >= 0 || n == Unlimited) {
l.Seats = n
}
case KeyAITasks:
if n, err := strconv.ParseInt(v, 10, 64); err == nil && (n >= 0 || n == Unlimited) {
l.AITasks = n
}
case KeyNotificationChannels:
l.NotificationChannels = splitList(v)
case KeyConnectors: