Skip to content

Plugin handlers: SDK types, scoped ProPR client, outbound HTTP, plugin state and the core-import lint rule #3548

Open

Description

@integry

Goal

Define how plugin code runs and what it can touch. Handlers of official plugins run in-process, but only through a narrow interface (input in, calls through ctx out) so the same plugin could later run out of process. This issue builds the interface and a way to invoke a handler; event delivery and inbound webhooks follow in the next two issues.

Handler interface

A plugin folder may contain handlers.ts exporting named async functions. A handler receives (input, ctx) and returns nothing or a small result. ctx is the only way a handler touches anything:

  • ctx.settings: the validated settings.
  • ctx.propr: a client limited to the permissions granted to this installation and to the plugin's repository limit. Initial operations: read a pull request, issue or task summary; list recent events; create an issue; create a task for an issue; comment on a pull request or issue; add or remove a label. Each call is checked against the grant and recorded with the plugin id as the actor. A call outside the grant throws and is logged.
  • ctx.http(connectionId?): fetch-like outbound HTTP that only reaches hosts listed in the manifest's outboundHosts, goes through the existing endpoint policy (HTTPS only, no private or loopback addresses by default, bounded size and time), and injects the named connection's credential. Handlers never receive raw secrets.
  • ctx.state: a small key-value store scoped to the installation (JSON values, size and key-count limits) for cursors and mappings such as "this pull request maps to that chat thread".
  • ctx.log: structured log lines returned to the caller of the handler; values are passed through the existing secret redaction.

Handlers must not import ProPR internals: enforce with a lint rule (restricted imports) for packages/plugins/**, allowing only @propr/shared types and the plugin SDK types.

Invocation

A core function runPluginHandler(installation, handlerName, input) loads the handler from the registry, builds ctx, applies a 30 second timeout and returns outcome, duration, error message and log lines. It never throws to its caller. The next issues call it from the dispatcher, the webhook route and commands.

Plugin test kit

packages/plugins/testing: a fake ctx (recorded propr calls, scripted http responses, in-memory state, captured logs) for plugin unit tests.

Acceptance criteria

  • With a fixture plugin: runPluginHandler runs a handler, returns its logs and outcome; a throwing handler and a handler that hangs past the timeout return a failed outcome without throwing.
  • ctx.propr refuses operations outside the granted permissions and outside the repository limit; allowed operations are attributed to the plugin in the audit trail and task events.
  • ctx.http refuses hosts not in outboundHosts, private addresses and plain HTTP; credentials are injected and never visible to the handler (sentinel test on handler-visible values and on logs).
  • ctx.state enforces its size and key-count limits and is deleted on uninstall.
  • The restricted-imports lint rule fails a fixture plugin that imports a core module.
  • Docs: handler interface in docs/docs/features/plugins.md and a new docs/docs/architecture/plugin-runtime.md.

Implementation

  1. Shared: handler SDK types (PluginContext, handler input envelopes) in packages/shared/src/pluginSdk.ts.
  2. Core: packages/core/src/plugins/pluginContext.ts (scoped client built on existing services, ctx.http on packages/core/src/extensions/endpointPolicy.ts, state store, logging with redaction) and pluginHandlerRunner.ts. Knex migration for plugin state.
  3. ESLint restricted-imports override for packages/plugins/** in eslint.config.js.
  4. packages/plugins/testing test kit.
  5. Tests with a fixture plugin in packages/core/test.

Notes

Depends on the installation state issue. Ordinary task runs stay one-shot: handlers observe and create new work, they never interact with a running task. ProPR runs on SQLite only.

Activity

  1. added
    base-3542-epic-plugin-system-xu8
    on Nov 14, 2026
  2. propr-dev commented on Nov 14, 2026

    @propr-dev
    Contributor

    🤖 AI processing has started for this issue using claude agent with claude-opus-5-5 model.

    I'll analyze the problem and work on a solution. This may take a few minutes.

    Processing Details:

    • Agent: claude
    • Model: claude-opus-5-5
    • Branch: 3548/claude-opus-5-5-plugin-handlers-sdk-types-20261114-1908-nxn
    • Base Branch: 3542-epic-plugin-system-xu8
    • Worktree: issue-3548-20261114-1908-claude-opus-5-5-nxn

    🔍 Track Task Execution

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    AI-doneauto-mergebase-3542-epic-plugin-system-xu8llm-claude-opus55propr-planned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions