Skip to content

feat(plugins): run-completed hook, richer send hook and agent plugin tools - #21

Draft
ashx-j wants to merge 11 commits into
mainfrom
feat/plugins-phase-5
Draft

ashx-j wants to merge 11 commits into
mainfrom
feat/plugins-phase-5

Conversation

@ashx-j

@ashx-j ashx-j commented Oct 30, 2026 •

Copy link
Copy Markdown
Owner

Phase 5 of the plugin system roadmap (#3, phase issue #9). It builds on #20, so until #14 to #20 merge this diff also shows their commits.

Plugins could see a message before it was sent, but not what happened after, and agents could list plugins but not use them. This adds a run-completed hook that never misses a run, gives the send hook the whole message, and lets agents drive plugins.

  • turns.afterRunCompleted(handler) runs once for every run that ends (completed, interrupted, failed, cancelled or rolled back), in order. It is built from the plugin's own events.stored stream and storage: after each ended run it saves the event's sequence, so runs that end while the plugin is off or the server is down arrive when the plugin starts again. The first registration starts from now.
  • turns.beforeDispatch now also gets the message id, a summary of each attachment (type, name, MIME type, size) and the model the message asked for.
  • Agent tools. t3_plugins_invoke calls a method a plugin registered and t3_plugins_set_enabled turns a plugin on or off. Both count as writes, so read-only and plan-mode sessions can't call them. Like t3_plugins_list, they only appear once a plugin is installed.
  • The tool policy item was already done in Phase 3: plugin write tools need the same access as built-in writes.

Changes from the roadmap (issue #9 is updated):

  • Not built yet:
    • turns.onRuntimeRequest, which would let a plugin answer approvals. It needs rules the user sets per plugin, which this doesn't have yet.
    • Context providers with composer chips. They need a send-path change for each chip, and the send hook already appends context.
    • Plugin skills. Each provider finds skills on its own (Claude reads skill folders, Codex its own list), so plugin skills need a decision per adapter.
    • Server-handled slash commands. A plugin's web slash command (feat(plugins): palette, keybinding and composer commands from plugins #19) can already call its server half over rpc.invoke.
  • afterRunCompleted keeps one saved position per registration, in registration order, rather than a name the plugin picks.

Measurements:

  • Send path, measured with a benchmark of PluginHooks.beforeDispatch over 5,000 messages: about 1 µs per message with no hooks and about 15 µs with one no-op hook. Sending a message also writes to the database, which takes milliseconds.
  • afterRunCompleted writes to the plugin's storage once per ended run, not once per event.
  • With no plugins installed nothing changes: no hooks, and none of the plugin MCP tools are advertised. AgentContextBudget.test.ts passes unchanged.

Test plugins: none new. The behaviour is covered by tests against fake event streams and the existing fixtures (workbench-plugin for the send hook, mcp-plugin for the MCP tools).

Verification:

  • api/turns.test.ts delivers runs that ended to a handler, skips a run still going, saves the position, and checks that a second activation resumes after the last handled run.
  • PluginMcpTools.test.ts checks the 2 new tools appear only with a plugin installed, a read-only session can't invoke, and a full-access one invokes and toggles a plugin through the host's actions.
  • PluginHost.test.ts and ThreadManagementService.test.ts pass with the richer hook message.
  • vp run check:changed passed.
  • Not verified: the 2 new tool descriptions with the mcp-tool-use eval, and a hook seeing a real provider turn. Both need paid agent turns.

Review: an adversarial review of #18 to #22 found issues in this PR; the fixes are in #23.


PR filed by Claude Opus 5.5 in Claude Code through T3 Code.

ashx-j and others added 11 commits October 31, 2026 21:22
…bility flag

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PluginHost discovers installed and dev plugins, loads enabled CommonJS
entries after the server is listening, and hands each a Promise-based API
for logging, settings, storage, RPC methods and channels. Failures mark the
plugin failed and never stop the server. Settings live beside T3's state
with secrets in the server secret store; storage is a lazily opened SQLite
file. Eight plugins.* WebSocket methods manage plugins, and the environment
advertises plugins: true.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An adversarial review found that reloading one plugin left plugins whose
folders vanished running, that a caller disconnecting mid-disable left a
plugin half torn down but still routed, that a misspelled access level
made a write method callable by read-only sessions, and that reload kept
old code for symlinked plugin folders. Lifecycle changes now run in the
host's scope, vanished plugins are stopped, access must be read or write,
and discovery resolves real paths. Activation and cleanups get deadlines,
calls stop routing before teardown, and plugins.json keeps unknown keys.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Settings gains a Plugins page for the selected environment: each plugin
with its status, failure, enable switch and reload, plus a settings form
generated from the manifest's JSON Schema with write-only secret fields
and a JSON fallback. The page follows plugins.subscribeStates only while
open; the form model lives in client-runtime for the later mobile screen.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ng and send hooks

Plugins can now follow stored orchestration events by type, read and act
on threads and projects, run scheduled work, see and extend outgoing
messages before they are sent, offer MCP tools to agents and serve HTTP
routes under /api/plugins/<id>, and read the server's version, descriptor
and redacted settings. The send hook runs in ThreadManagementService.dispatch
with a 2 s deadline and fails open; with no hooks it is one Ref read.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… writes

An adversarial review found that a send hook appending to /goal clear
turned it into setting a goal, that the SDK promised a veto nothing
honoured, that several event types merged out of sequence order, that a
schedule could outlive its plugin, and that plugin write tools skipped the
caller's mode limits. Hooks now skip slash commands, veto is gone from the
SDK, multi-type event streams stay ordered, schedules and hooks stop on
the deactivation signal, API calls end after cleanups, plugin write tools
need full access like environment writes, and tool schemas must be objects.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Plugins could only run on the server. The server now serves each active
plugin's web bundle, and the web app loads it once an active plugin has a
web part: a starter follows plugin state after idle, and the loader fetches
bundles with the connection's credentials and imports them from blob URLs.
Bundles share the app's React, atom hooks and UI kit through a host object.

Plugins can add right panels, listed in the add menu and the empty panel,
and replace their generated settings form. An unloaded plugin's panel shows
"Plugin not active" with a close button. The desktop CSP allows blob scripts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Web plugins could add panels but nothing users could run from the
keyboard. Plugins can now register command palette commands that users
bind as plugin.<pluginId>.<commandId>, and slash commands in the composer
that run plugin code. They can also navigate and load files from their
assets folder, which the server serves under /api/plugins/<id>/assets/*.

The SDK gains a Vite preset that builds web.js against T3's React and UI
kit, keeping only the names a plugin uses, and typed UI components.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…om plugins

Web plugins could add panels and commands but not change how T3 looks or
how conversations read. A plugin's themes/ folder is now published through
the environment theme service, so its themes reach every client. Web
plugins can show composer banners, draw their own MCP tool calls in the
timeline, draw fenced code of a language in chat messages, and inject
styles. Everything is removed when the plugin unloads.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tools

Plugins could see a message before it was sent but not what happened
after, and agents could list plugins but not use them.

turns.afterRunCompleted delivers every ended run in order, saving its
position in the plugin's storage so runs that end while the plugin is off
arrive when it starts. turns.beforeDispatch now gets the message id,
attachment summaries and the requested model. Agents get
t3_plugins_invoke and t3_plugins_set_enabled, gated as writes and only
advertised once a plugin is installed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ashx-j
ashx-j force-pushed the feat/plugins-phase-5 branch from e95faca to 6738076 Compare October 31, 2026 21:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XXL vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant