Skip to content

Let plugins intercept CLI invocations and agent tool calls - #2444

Open
SawyerHood wants to merge 1 commit into
bb/garden-3-app-replacement-slotsfrom
bb/garden-4-invocation-interception
Open

Let plugins intercept CLI invocations and agent tool calls#2444
SawyerHood wants to merge 1 commit into
bb/garden-3-app-replacement-slotsfrom
bb/garden-4-invocation-interception

Conversation

@SawyerHood

@SawyerHood SawyerHood commented Aug 25, 2026

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

A policy plugin had no way to observe or block a bb command or a bb-defined agent tool call before it ran.

What changed

  • Plugin API: bb.events.on("experimental_invocation.before", handler) returning { allowed, reason? }; the server runs every loaded plugin's handlers in deterministic order (plugin-service.ts, plugin-api.ts) and records invocation events (packages/domain change kinds, event-pruning).
  • POST /api/v1/plugins/invocations/preflight (apps/server/src/routes/plugins.ts); the CLI asks it once per executable command (apps/cli/src/invocation-preflight.ts, registered with the lazily loaded command groups in index.ts) and before proxying a plugin command. It fails open when the server is unreachable or predates the route, and blocks on an explicit block, a malformed 2xx, any other non-2xx, or a server that accepts the connection and then goes quiet (headers/body timeout). bb guide and bb manager are never preflighted.
  • apps/server/src/internal/tool-calls.ts consults the same policy for bb-defined agent tools; a handler failure returns a tool error to the agent instead of failing the turn.
  • Fake plugin host (packages/plugin-sdk/src/testing) supports scripted decisions; the plugin-authoring skill and bb guide plugins document the hook.

No wire change. Prerequisite: #2443 (stack order only).

Open decision for reviewers: fail-open vs fail-closed when the server is down, and whether a per-handler timeout is required before this ships.

How you verified

turbo run typecheck; turbo run test for @bb/cli (invocation-preflight.test.ts, packaged plugin build), @bb/server (plugin-invocation-events.test.ts, internal tool calls), @get-bb/plugin-sdk (fake host), @bb/db.

Fixes: none (upstream stack split).

AGENT GENERATED

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant