Automations phase 2: chaining, refinements, dry run

Chaining: spec gains calls:[ids] + calledOnly. On fire, a task calls its
same-owner callees in order; each callee evaluates its OWN condition and
may call onward. Safety: write-time cycle rejection (owner-graph DFS) plus
a runtime visited-set + depth cap (5); calledOnly tasks skip the schedule;
existing per-task fire caps and the owner daily email cap still apply
across the chain. The LLM never chooses calls — the user wires the graph.

Refinements: AgentTask.refinements jsonb (migration 026) stores added
constraints; the UI composes prompt+refinements into the compile text and
shows removable chips. Dry run: condition-check is split from fire() so
POST /api/agent/dry-run evaluates a spec without acting or recording —
the 'Extend → Try it' preview ('result would be false right now').

UI: detail view gains the 'If true, call' card (picker disables
loop-creating options), refinement chips + Extend/Try it/Add flow, called-by
breadcrumb, and a 'when called' frequency label.

Verified: full DB integration suite under -race (chaining fires callees,
cycle rejected at write + runtime guard terminates a DB-injected cycle,
calledOnly skips schedule, dry run records nothing, refinements capped),
db-converge + atomicity, web lint/SSR/build, browser regression extended
for chaining + refinement + dry run.
This commit is contained in:
Andrew S Erwin
2026-11-25 14:57:41 -06:00
parent 10d4c898d2
commit c84d694a03
10 changed files with 692 additions and 39 deletions
+22 -1
View File
@@ -85,9 +85,15 @@ let lastNextcloudConnect = null
const agentTasks = [{
id: 'task-1', name: 'Watch the price', summary: 'Checks flights.example hourly and emails when below $400',
spec: { condition: { type: 'url_watch', url: 'https://flights.example/q/123', question: 'price?', op: 'lt', threshold: 400 }, action: { type: 'email', to: 'david@email.com' }, pollMinutes: 60, once: false },
prompt: 'when the price on flights.example drops below $400, email david@email.com', groupId: 'g1',
prompt: 'when the price on flights.example drops below $400, email david@email.com', groupId: 'g1', refinements: [],
runCount: 2, errorCount: 1,
enabled: true, status: 'active', fireCount: 2, lastCheckedAt: '2026-11-23T00:00:00Z', lastFiredAt: null, version: 1, createdAt: '2026-11-20T00:00:00Z',
}, {
id: 'task-2', name: 'Lisbon hotel', summary: 'Checks Hotel Alfama and saves a bookmark',
spec: { condition: { type: 'url_watch', url: 'https://example.com/hotel', question: 'rate?', op: 'lt', threshold: 180 }, action: { type: 'bookmark', url: 'https://example.com/hotel', title: 'Hotel deal' }, pollMinutes: 120, once: false, calledOnly: true },
prompt: 'check if Hotel Alfama is under €180 and save a bookmark', groupId: 'g1', refinements: [],
runCount: 1, errorCount: 0,
enabled: true, status: 'active', fireCount: 0, lastCheckedAt: null, lastFiredAt: null, version: 1, createdAt: '2026-11-20T00:00:00Z',
}]
const agentGroups = [{ id: 'g1', name: 'Travel', position: 0, version: 1 }]
const agentRuns = [
@@ -341,6 +347,8 @@ const api = http.createServer(async (req, res) => {
} else result = agentGroups
} else if (url.pathname === '/api/agent/compile' && req.method === 'POST') {
result = { name: 'Recompiled task', spec: { condition: { type: 'url_watch', url: 'https://flights.example/q/123', question: 'price?', op: 'lt', threshold: 350 }, action: { type: 'email', to: 'david@email.com' }, pollMinutes: 60, once: false }, summary: 'Emails david@email.com when below $350' }
} else if (url.pathname === '/api/agent/dry-run' && req.method === 'POST') {
result = { matched: false, detail: 'value 462 vs lt 350' }
} else if (/^\/api\/agent\/tasks\/[^/]+$/.test(url.pathname) && req.method === 'PATCH') {
const t = agentTasks.find(x => x.id === url.pathname.split('/')[4])
if (!t) { res.writeHead(404); res.end('{}'); return }
@@ -943,6 +951,19 @@ try {
await page.getByText('Recompiled proposal').waitFor()
await page.getByRole('button', { name: 'Apply changes' }).click()
await page.getByText('Automation updated').waitFor()
// Phase 2: chaining — call another automation (loop options disabled).
await page.getByRole('button', { name: '+ Call an automation' }).click()
await page.getByRole('combobox').last().click()
await page.getByRole('option', { name: 'Lisbon hotel' }).click()
await page.getByRole('button', { name: 'Add', exact: true }).click()
await page.getByText('IF TRUE').waitFor()
// Phase 2: refinement via Try it (compile + dry run, nothing fires).
await page.getByPlaceholder('Also require a checked bag included').fill('nonstop only')
await page.getByRole('button', { name: 'Try it' }).click()
await page.getByText('Condition understood.', { exact: false }).waitFor()
await page.getByRole('button', { name: 'Add to automation' }).click()
await page.getByText('Refinement added').waitFor()
await page.getByText('nonstop only', { exact: true }).waitFor()
// Overview: global runs carry the automation name.
await page.getByRole('button', { name: 'All automations' }).click()
await page.waitForURL('**/automations')