refactor(desktop,shared,api): consolidate the three GitHub-shaped seam surfaces

Merged
SA
3mo ago
+254-162

Why

Eight provider agents building in parallel off #6571 all hit the same three walls in the first hour, and each patched them differently. This lands one answer so they rebase onto it instead of merging eight divergent copies. Every provider PR (#6586, #6587, #6589, #6591, #6592, #6593 + Google, Circleback) rebases onto this.

The three surfaces

1. Options → namespaced by provider. OptionKey was a flat "kind of thing" namespace; people for GitHub is numeric ids and for Slack is Slack user ids, projects means different things to Linear and Sentry. Five agents each added a key to types.ts. Now options.github.repositories, options.slack.channels; nobody touches types.ts again.

2. MatchableEvent → provider-typed, discriminated by provider. It was GitHub's normalized event under a generic name (repositoryId, isFork, subjectAuthorId mean nothing to Slack), so every agent stuffed real fields into MatchContext.<provider>. Now BaseMatchableEvent holds only what's shared (eventType, actorId, actorLogin, body), each provider defines <Name>MatchableEvent, and MatchContext is just { ownerIds } — the one genuinely cross-provider thing, since it's how me resolves. triggerMatches switches on event.provider and refuses a config/event provider mismatch.

3. One dispatcher. dispatchMatchingTriggers was GithubPayload-typed, so three agents forked it. Its body is provider-agnostic — candidate query, identity map, match loop, QStash publish. Lifted to apps/api/src/lib/automations/dispatchMatchingTriggers.ts selecting by kind = event.provider; GitHub's file is now a ~60-line normalizer that calls it.

Also SentenceContext.triggerId (three agents needed it) and main's a11y lint failure in TerminalAgentAutoResume (was painting every provider PR red).

Verification

Zero behaviour change for GitHub. Typecheck and lint clean across all 38 packages.


Summary by cubic

Consolidates the provider seam: options are namespaced by provider, events are provider-typed, and dispatching is centralized. This removes GitHub-shaped assumptions and unblocks new providers without divergent copies. GitHub behavior is unchanged.

  • Provider options: ProviderOptions is now namespaced (e.g. options.github.repositories, options.github.people). Update reads/writes from flat keys to namespaced keys. Each hook returns its own top-level key (e.g. { github: {...} }).
  • Events and matching: MatchableEvent is a union discriminated by event.provider; shared fields live on BaseMatchableEvent. MatchContext is now { ownerIds } only. GitHub adds names, repositoryId, isFork, etc. triggerMatches switches on event.provider and rejects a config/event provider mismatch.
  • Dispatching: Introduces apps/api/src/lib/automations/dispatchMatchingTriggers.ts, a provider-agnostic dispatcher; the GitHub webhook normalizes then calls it. Candidate query, identity lookup, and QStash publish now exist once.
  • UI: SentenceContext includes optional triggerId for rows that render per-trigger artifacts. Fixes an a11y lint by replacing a span role="status" with output.