Repository navigation
Description
Summary
Design and implement a plugin-defined reactive behavior system for the GitHub channel, enabling Junior to respond to GitHub events beyond explicit @junior mentions. Builds on #311 (the @mention entry point) by adding a behavior arbitration layer, new plugin hooks, and constrained execution modes.
The core concept: GitHub is a peer channel to Slack with its own system prompt, tools, and response surface. Plugins declare named behaviors and claim them in response to specific GitHub events. Core arbitrates claims and runs at most one agent per event.
Background
Issue #311 covers Phase 1: @junior mention in a comment → full agent turn → GitHub comment reply. This issue covers the architecture needed to support reactive event handling — where GitHub events from other bots or CI systems trigger predefined plugin behaviors.
Two distinct turn types both respond on GitHub:
| Explicit mention | Reactive event | |
|---|---|---|
| Trigger | @junior in comment |
Bot comment, CI result, etc. |
| Mode | conversation |
reactive_behavior |
| Agency | Full — user invoked | Predefined behavior, constrained |
| Direct push | Allowed if user asks | Never |
| Create PR | Yes | Draft only, if configured |
| Opt-in | No | Yes — repo-scoped, default off |
Proposal
New plugin hooks
Add two hooks to AgentPluginHooks in @sentry/junior-plugin-api:
behaviors() — plugins declare named behavior definitions at startup. Auditable and validatable at startup time.
behaviors?(ctx: BehaviorRegistrationContext): Record<string, AgentBehaviorDefinition>;webhookEvent() — invoked per GitHub webhook delivery. Returns a claim to invoke a named behavior, or ignored/rejected. No agent.dispatch in context — hooks propose, core disposes.
webhookEvent?(ctx: WebhookEventHookContext): Promise<WebhookEventResult | void>;Return type is a claim referencing a declared behavior:
type WebhookEventResult =
| { kind: "ignored"; reason?: string }
| { kind: "rejected"; httpStatus: 400 | 401 | 403 | 422; reason?: string }
| { kind: "claim"; behaviorId: string; idempotencyKey: string; input: string; variables?: Record<string, unknown>; target?: GitHubResponseTarget };Behavior definitions
Behavior definitions are declared at startup and include constrained execution policy:
interface AgentBehaviorDefinition {
channel: "github";
mode: "conversation" | "reactive_behavior";
prompt: { profile: string; systemPromptAddon?: string };
toolPolicy: ToolPolicy; // enforced by runner, not prompt guidance
limits?: { maxModelTurns?: number; maxToolCalls?: number };
constraints?: { allowDirectPush: false; requireDraftPullRequest?: boolean };
response: { destination: "source_thread" | "source_comment"; format?: "github_markdown" };
}Extended tools() hook
Extend the existing tools() context with channel and run so plugins can conditionally register tools:
interface ToolRegistrationHookContext {
channel: AgentChannelContext; // { kind: "github", owner, repo, ... } or { kind: "slack", ... }
run: AgentRunContext; // { mode: "conversation" | "reactive_behavior", behaviorId?, toolPolicy? }
// ...existing Slack compat fields preserved
}Multi-plugin safety: claim arbitration
Core collects all plugin claims before scheduling:
- 0 claims → ACK, no run
- 1 claim → validate + schedule exactly one run
- 2+ claims → ACK (prevent retry storm), log conflict, alert, no run
Storage-level uniqueness enforced on (source.platform, source.sourceEventId) for webhook-originated runs.
Delivery abstraction
Refactor dispatch runner to use a delivery adapter interface, replacing hardcoded Slack post calls:
SlackDeliveryAdapter— wraps existing Slack post logicGitHubDeliveryAdapter— posts comments/PRs via GitHub App installation token
Reactive behavior opt-in
Default: disabled everywhere. Reactive behaviors require explicit repo-scoped enablement:
interface GitHubBehaviorEnablement {
enabled: boolean;
owner: string; repo: string;
plugin: string; behaviorId: string;
eventTypes: string[];
actorAllowlist?: string[]; // which bots/apps can trigger
bodyPatterns?: string[];
}Implementation phases
Phase 1 (prerequisite — #311): GitHub adapter, @junior mention handling, GitHubDeliveryAdapter, GitHub system prompt.
Phase 2: behaviors() and webhookEvent() hooks, behavior arbiter, claim arbitration, storage uniqueness, behavior definitions validated at startup.
Phase 3 (gated on runner enforcement): Runner-level tool policy filtering + executor-level rejection, channel/run context in beforeToolExecute/sandboxPrepare, GitHub plugin's first reactive behavior (considerAndAddress for CI bot findings), opt-in config model.
Stop conditions for Phase 3
- Runner must filter tools by
toolPolicybefore model exposure - Executor must reject disallowed tool calls at runtime (not prompt-only)
- GitHub write credentials must not be injected in reactive mode
- Multiple claim arbitration must be enforced before shipping
- Reactive behaviors must be repo-scoped opt-in, default off
Related
- Add GitHub @mention entry point for Junior #311: Add GitHub @mention entry point for Junior (Phase 1 prerequisite)
- Design canvas: https://sentry.slack.com/docs/T024ZCV9U/F0B6UGF387L
Action taken on behalf of David Cramer.
Activity
dcramer commentedon Jun 2, 2026
Updated direction: install-owned event prompts
After a design pass, the preferred shape is not plugin-owned behavior claims. The cleaner boundary is:
Example install file:
Key model:
.mdfile underapp/events/**/*.md.(bindingId, sourceEventId).Core should validate every event Markdown file at startup. Bad event ids, unsupported filters, unsupported context blocks, invalid delivery targets, or unsafe policy should fail fast before partial registration.
Prompt compilation should keep hard boundaries:
Main concerns to carry into implementation:
whensimple in V1: exact matches, lists, includes, and maybe no regex until needed.app/events/**/*.mddeterministically in deployed installs.Implementation should start with specs: add an event prompt spec, link it from plugin/runtime/dispatch specs, then build the file loader/validator before wiring specific GitHub or Slack producers.
feat(events): Add install-owned event prompts
fix(slack): Initialize event prompt bot context
feat(events): Allow silent event prompt runs
feat(events): Add install-owned event prompts
fix(slack): Initialize event prompt bot context
feat(events): Allow silent event prompt runs
test(events): harden event prompt coverage
ref(events): Split Slack webhook event handling
ref(events): Trim event binding surface
feat(events): Add install-owned event prompts
fix(slack): Initialize event prompt bot context
feat(events): Allow silent event prompt runs
test(events): harden event prompt coverage
ref(events): Split Slack webhook event handling
ref(events): Trim event binding surface
fix(events): Use bound dispatch options for event prompts
sentry-junior commentedon Nov 9, 2026
Obsolete: event automations replaced plugin-defined reactive hooks (
junior-github/src/events/declarations.ts,chat/event-automations/, match filters in #2572). The remaining gaps are in #2362 and #2051.Closed during a tracker cleanup. Reopen if this still needs separate tracking.