feat(automations): Linear trigger provider

Merged
SA
3mo ago
+756-5

Summary

Adds the Linear trigger provider to automations. Four events, per the brief:

eventsentencefilters
issue.createdIssue created in team in [project] with label [label]teams · projects · labels
issue.status_changedIssue moved to [status] in team in [project] with label [label] assigned to [assignee]teams · projects · labels · toStatus · assignee
issue.assignedIssue assigned to [assignee] in team in [project] with label [label]teams · projects · labels · assignee
cycle.endedCycle ended in teamteams

What changed

  • packages/shared/automation-triggers.ts — linearTriggerConfigSchema gains labels, toStatus (scopes) and assignee (actor), plus issue.assigned. describeTriggerProblems: teams required, assignee must be non-empty or Anyone (same rules as GitHub's repositories/actor).
  • packages/shared/automation-matching/linear.ts — LinearMatchableEvent (teamId, projectId, stateId, assigneeId, labelIds, names) joins the MatchableEvent union; linearEventNames maps a Linear delivery to product events using updatedFrom (Linear's previous-values map); linearTriggerMatches applies the filters. null teams matches nothing; optional narrowings treat null as "any" (GitHub convention). One case "linear" in triggerMatches.
  • apps/api/.../integrations/linear/callback/route.ts — upserts the connecting user's Linear identity (see below).
  • apps/api/.../integrations/linear/webhook/route.ts — the existing route (signature verified on the raw body first, unchanged) now normalizes each entity delivery into a LinearMatchableEvent, records deliveries a trigger can name as automation_events (provider linear, idempotent on the Linear-Delivery header) and hands off to the shared @/lib/automations/dispatchMatchingTriggers, per connection, after the task sync. Only deliveries with a named event are recorded: Linear sends every attachment/comment edit to the same hook and most Issue.updates touch nothing a trigger filters on.
  • packages/trpc integration.linear — getTriggerOptions (teams, projects, labels, workflow states in one GraphQL round trip; state/label names are suffixed with the team key since they repeat across teams) and listLinkedPeople (user_identities provider=linear).
  • desktop providers/linear/ — grammar, sentence renderer (existing ScopeChip/ActorChip only), useLinearOptions returning { linear: { teams, projects, labels, statuses, people } }; one registry line and one useProviderOptions line. No seam files touched beyond those.

Event semantics (defaults taken; flagged to the coordinator)

  • issue.assigned fires when assigneeId becomes non-null: new assignment, reassignment, and an issue created with an assignee. Unassign does not fire.
  • issue.status_changed = Issue.update with updatedFrom.stateId; not on create.
  • cycle.ended = Cycle.update where completedAt goes null → set.
  • toStatus is an optional narrowing (Any status by default), like GitHub's branches.

Not in this PR / needs an outside action

  • Identity: the Linear connect callback now upserts the connecting user's user_identities row (provider linear, externalId = viewer id, scoped to the Linear workspace id), which is what me and the assignee people list resolve through. Other members still have no way to link a Linear account; that flow is deliberately not built here.
  • Superset's Linear OAuth-app webhook is not subscribed to Cycles (zero Cycle.* deliveries in three days of ingest). cycle.ended is verified by signed replay; it needs the resource enabled in Linear's app settings to fire for real.
  • No migration: automation_triggers.kind/integration_provider already carry linear; the config lives in jsonb.

Verification

Desktop over CDP against this workspace's API (renderer :8605, API :8601, CDP :9333):

  • Add Trigger → Linear → Issue… → Status changed; picked team Superset, status Duplicate · SUPER, label Agent · SUPER from real Linear data; Save → "Triggers saved"; reload → sentence re-renders from the persisted row with labels resolved. Also added Cycle ended and Issue assigned; Save with empty teams was refused with "Some triggers need additional configuration" and both team chips marked.
  • automation_triggers rows: kind=linear with the full config (status_changed / assigned / cycle.ended).

Signed replays at POST /api/integrations/linear/webhook (HMAC with LINEAR_WEBHOOK_SECRET, Linear-Delivery header):

  • a real Issue.update status change from ingest → automation_events row (Issue.update, linear:issue:<id>, title SUPER-1527 …), matcher selected the trigger and reached qstash.batchJSON (QStash rejects the loopback URL locally, as for every provider); replaying the same delivery id → Not recorded as automation event (duplicate delivery).
  • synthetic issue.assigned and cycle.ended payloads → recorded + selected; a status change to a different state → recorded, no match (reason: "status").

bun run typecheck exit 0 in shared, trpc, api, desktop. bun run lint fails only on a pre-existing TerminalAgentAutoResume.tsx a11y error on main; biome is clean on every touched file.

Summary by CodeRabbit

  • New Features
    • Added Linear automation triggers for issue creation, assignment, status changes, and cycle completion.
    • Added filters for teams, projects, labels, statuses, and assignees, including an “Anyone” option.
    • Added Linear trigger configuration and option selection in the automation editor.
    • Linear webhook events now trigger matching automations after synchronization.
    • Linked Linear users are available as assignee options.
    • Linear identities are saved during OAuth sign-in.