Repository navigation
feat: safe, revertable plugin system with agent control - #1
Josephivgi wants to merge 2 commits into
Conversation
- contracts: PluginManifest/PluginRecord/journal schemas + plugins API group on the environment HTTP API (list/install/enable/disable/ remove/revert) and shared plugin contract exports - server: PluginManager service — manifest validation, capability allowlist, sandboxed asset resolution, journal snapshots so every mutation can be reverted; /api/plugin-assets route serving plugin assets with nosniff + sandboxed CSP for HTML - mcp: plugins toolkit (list/install/enable/disable/remove/revert) so agents have full lifecycle control - web: Plugins settings panel, useEnvironmentPlugins hook, PluginContributions (header icons, sandboxed panels, theme css) mounted in the chat header, settings route/search/sidebar entries - examples: devin-icon plugin + plugins README Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 92c893c87a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| export function useEnvironmentPluginsApi(environmentId: EnvironmentId | null): PluginsApi | null { | ||
| const prepared = usePreparedConnection(environmentId); | ||
| if (prepared._tag !== "Some") return null; | ||
| return makePluginsApi(prepared.value.httpBaseUrl); |
There was a problem hiding this comment.
Memoize the plugins API per environment
When a connected chat or settings view uses this hook, makePluginsApi returns a new object on every render. useEnvironmentPlugins keys its fetch effect on api and updates plugin state after each response, so each list request triggers a render and another /api/plugins request indefinitely. Memoize the API by httpBaseUrl so state updates do not restart the fetch.
Useful? React with 👍 / 👎.
| for (const href of contributes.themeCss ?? []) { | ||
| themeCss.push({ pluginId: plugin.manifest.id, href }); |
There was a problem hiding this comment.
Treat the theme stylesheet as a single asset path
PluginContributes.themeCss is a single PluginAssetPath string, not an array. Iterating it here creates one contribution per character, so the generated links point to individual characters rather than the stylesheet and the plugin theme is not applied. Add the single path directly to themeCss instead.
Useful? React with 👍 / 👎.
| seq, | ||
| plugins: { | ||
| ...state.plugins, | ||
| [candidate.pluginId]: { enabled: true, installedAt: now, updatedAt: now }, |
There was a problem hiding this comment.
Restore the removed plugin's previous state on revert
If a disabled plugin is removed and then reverted, this branch recreates it as enabled, so the revert activates a plugin that was disabled before removal. It also drops the prior source and resets its timestamps. Preserve and restore the pre-remove PluginStateEntry so revert undoes the removal rather than creating a new default entry.
Useful? React with 👍 / 👎.
| ...(isHtml | ||
| ? { "content-security-policy": "sandbox allow-scripts allow-forms allow-popups" } | ||
| : {}), |
There was a problem hiding this comment.
Sandbox SVG assets served by the plugin route
If an installed plugin contributes an SVG containing script and a user opens its asset URL (for example, through the plugin's href), the route serves it as an SVG document but only adds a sandbox CSP for HTML. The SVG script can then run as a same-origin document and access the app's DOM and APIs, bypassing the panel iframe sandbox. Apply the SVG sandbox policy to these responses too.
Useful? React with 👍 / 👎.
| return; | ||
| } | ||
| for (const entry of entries) { | ||
| if (limit.files > MAX_PLUGIN_FILES) return; |
There was a problem hiding this comment.
Reject plugin packages that exceed the file-count limit
When a source contains more than 256 files, this walk returns without recording a problem, so checkPluginDir accepts the package. Installation then copies the entire source tree rather than the scanned file list, bypassing the file-count and remaining size checks and potentially copying an unbounded amount of data into the state directory. Record a refusal at the limit and copy only validated files.
Useful? React with 👍 / 👎.
| seq, | ||
| plugins: { | ||
| ...state.plugins, | ||
| [candidate.pluginId]: { enabled: true, installedAt: now, updatedAt: now }, |
There was a problem hiding this comment.
Restore the removed plugin's previous state on revert
If a disabled plugin is removed and then reverted, this branch recreates it as enabled, so the revert activates a plugin that was disabled before removal. It also drops the prior source and resets its timestamps. Preserve and restore the pre-remove PluginStateEntry so revert undoes the removal rather than creating a new default entry.
AGENTS.md reference: AGENTS.md:L74-L74
Useful? React with 👍 / 👎.
| headers: { "content-type": "application/json" }, | ||
| body: JSON.stringify(input.body), | ||
| }; | ||
| const response = await fetch(`${input.baseUrl}${input.path}`, init); |
There was a problem hiding this comment.
Normalize the base URL before appending plugin paths
When a prepared connection's httpBaseUrl ends in /—as configured targets serialized with URL.toString() do—this concatenation requests //api/plugins instead of the registered /api/plugins route, so plugin management fails for that environment. pluginAssetUrl uses the same construction and breaks asset URLs in that case; normalize the base URL before appending either path.
AGENTS.md reference: AGENTS.md:L21-L21
Useful? React with 👍 / 👎.
|
|
||
| const readJournal = (): Array<StoredJournalEntry> => { | ||
| const raw = readPluginFileGuarded(journalPath, MAX_JOURNAL_READ_BYTES); | ||
| if (raw === null) return []; |
There was a problem hiding this comment.
Keep journal history readable as it grows
Once journal.jsonl grows past 1 MiB, readPluginFileGuarded returns null and this function treats the entire journal as empty, while mutations continue appending to it. From then on the UI loses the history and revert cannot undo any operation. Retain a bounded tail or rotate the journal instead of discarding all history.
AGENTS.md reference: AGENTS.md:L74-L74
Useful? React with 👍 / 👎.
| headers: { "content-type": "application/json" }, | ||
| body: JSON.stringify(input.body), | ||
| }; | ||
| const response = await fetch(`${input.baseUrl}${input.path}`, init); |
There was a problem hiding this comment.
Use the prepared connection's authorization for plugin API calls
When the UI manages a prepared connection using Bearer or DPoP authentication, these fetches send only cookies and content type, omitting the connection's authorization headers and proof. EnvironmentAuthenticatedAuth then rejects list and mutation requests, making plugin management unusable for those remote sessions. Route these calls through the shared environment HTTP auth client.
AGENTS.md reference: AGENTS.md:L21-L21
Useful? React with 👍 / 👎.
| return `${api.baseUrl}/api/plugin-assets/${encodeURIComponent(pluginId)}/${assetPath | ||
| .split("/") | ||
| .map(encodeURIComponent) | ||
| .join("/")}`; |
There was a problem hiding this comment.
Mint media tickets for plugin asset URLs
For a connection authenticated with Bearer or DPoP, this builds a bare asset URL without a wsTicket. The <img>, <link>, and iframe requests cannot attach authorization headers, while the asset route authenticates them as media requests; icons, panels, and theme stylesheets therefore fail to load in those remote sessions. Mint a media ticket for the asset URLs.
AGENTS.md reference: AGENTS.md:L21-L21
Useful? React with 👍 / 👎.
- t3_plugins_list: omit parameters (Schema.Struct({}) serializes to
{"not":{"type":"null"}} and crashes McpSchema.Tool registration,
preventing server boot)
- pluginsApi: strip trailing slashes from httpBaseUrl so /api paths
hit the Vite proxy instead of returning index.html
- propagate plugin mutations across mounted views via a change bus
plus visible-tab polling, so header icons update live
- surface PluginRefusedError.problem as detail on the 400 response
so refusal reasons reach the UI
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
E2E verification — plugin systemTested on Two blocking bugs were found by testing and fixed in Verified
|
Thread transfer impact
This comment will update automatically after the next completed run. |
Problem
T3 Code has no extension mechanism. There is no way to add UI contributions (header icons, panels, themes) without forking the app, and agents driving the server have no way to manage extensions.
Change
Adds a declarative plugin system with safety and reversibility built in:
packages/contracts):PluginManifest/PluginRecordschemas, a capability allowlist (ui:header-icon,ui:panel,ui:theme-css), and a plugins group on the environment HTTP API (list,install,enable,disable,remove,revert).apps/server/src/plugins):PluginManagerservice validates manifests, enforces the declared capability allowlist, copies assets into the server plugins dir, resolves assets only inside a plugin's own directory, and journals a snapshot before every mutation so install/enable/disable/remove can be reverted./api/plugin-assets/<pluginId>/<asset>serves assets withnosniffand a sandboxed CSP for HTML.apps/server/src/mcp/toolkits/plugins): five MCP tools (t3_plugins_list/install/enable/disable/remove/revert) give agents the full lifecycle.apps/web): a Plugins settings panel (install by path, enable/disable switch, remove, revert-last-change), auseEnvironmentPluginshook with cross-view propagation (event bus + visible-tab polling), andPluginContributionsin the chat header renderingui:header-iconbuttons and sandboxed-iframeui:panelcontributions plusui:theme-cssstylesheets.examples/plugins): adevin-iconheader-icon plugin and a README describing the manifest format and safety model.Scope
Feature work on this fork (user-requested plugin system). Bug-fix-only scope of upstream does not apply here.
Verification
vp run typecheck: clean across all workspaces.vp check: 0 errors.vp test run src/cli/: pre-existing Windows quoting/launcher failures inup/pair/invocationtests, none related to plugins.Done by Devin (Cognition AI).
Link to Devin session: https://app.devin.ai/sessions/013a096f76254db791df0bf496875fb8
Open in Devin Desktop: https://app.devin.ai/desktop/session/013a096f76254db791df0bf496875fb8?variant=devin
Requested by: @Josephivgi