Plugin author

From WrongStack/WrongStack · View interactive version

Plugin author is an AI agent skill from the GitHub repository WrongStack/WrongStack. WrongStack plugin authoring: register tools, hooks, slash commands and host API extensions with config and clean teardown. Use when implementing tools, hooks or host API extensions in packages/plugins; verify contracts from current source and test multiple instances, failed setup and reload.

How to use this skill

Skill file

Plugin Author — WrongStack

Selection card

Overview

Implement the current Plugin/PluginAPI contracts from packages/contracts/src/types/plugin.ts.

Plugin state must remain reachable for teardown and correctly scoped to its

owner; “put everything at module scope” is not a safe universal rule.

Rules

  1. Inspect a neighboring plugin, the loader, registration views and host wiring.

Use actual API/schema defaults; derive plugin counts from the catalog.

  1. Own timers, watchers, listeners, background promises and counters per instance

or host. Use a factory/closure or API-keyed state where supported. Module

singletons require evidence that instances cannot overlap.

  1. Make setup/reload and teardown consistent with the host contract. Teardown

releases every acquired resource, including partial setup and failure paths,

and does not erase persistent user data.

  1. Fence async completion by owner/generation after awaits. Cancel or ignore stale

work after unload; fire-and-forget initialization still needs error handling.

  1. Configure options under config.extensions[plugin-name] and validate them with

the actual schema. Loading enablement and plugin options are distinct surfaces.

  1. Register unique tool names and honest permissions/mutating metadata. Tool

names are not guaranteed to exist on every minimal host; check optional APIs.

Implementation contract

declarations. Health reports real state; include teardown/health according to

project conventions even for simple plugins.

error behavior. Read the executor's current handling before choosing returned

errors versus thrown validation/execution failures.

block an operation merely by returning a decision.

calls through host services instead of handling secret credentials directly.

not remove a successor's tool or another plugin's hook.

Skeleton

Shape only — copy apiVersion, config handling and helpers from a neighbouring

plugin, and re-read packages/contracts/src/types/plugin.ts before relying on a field.

~~~ts

import type { Plugin } from '@wrongstack/contracts/types';

export function createExamplePlugin(): Plugin {

const disposers: Array<() => void> = []; // per instance, not module scope

return {

name: 'example',

version: '0.1.0',

apiVersion: '^0.1.10', // match the neighbours' current value

capabilities: { tools: true, hooks: true },

async setup(api, opts) {

api.tools.register({

name: 'example_count',

description: 'Count lines in a project file. Read-only.',

inputSchema: { type: 'object', properties: { path: { type: 'string' } }, required: ['path'] },

permission: 'auto',

mutating: false,

async execute(input, ctx, { signal }) { /* bounded, abortable work */ },

});

disposers.push(() => api.tools.unregister('example_count'));

disposers.push(api.registerHook('PostToolUse', 'edit', async () => undefined));

disposers.push(api.onConfigChange(() => { /* re-read options */ }));

opts?.signal?.addEventListener('abort', () => { /* stop partial setup */ });

},

async teardown() {

for (const dispose of disposers.splice(0).reverse()) dispose();

},

async health() {

return { ok: true };

},

};

}

~~~

Registration methods return disposers (registerHook, onEvent, onPattern,

onConfigChange, registerSystemPromptContributor); keep each one and call it in

teardown, newest first. Tool permission is auto, confirm or deny;

mutating: true for anything that writes, sends or spends.

Integration

  1. Implement under packages/plugins/src/<name>/ and add its named export.
  2. Add the actual package subpath export. The official build driver discovers

plugin entrypoints from the exports map.

  1. Wire first-party factories through the current CLI plugin wiring when needed.
  2. If extending PluginAPI, update types, implementation/init and host forwarding

together; add consumer tests. Determine compatibility impact from the real API.

  1. Use official manifest/catalog writers rather than manually updating generated

plugin inventories.

Validation

Cover registration, configuration errors, two hosts/instances when supported,

partial setup, repeated close, reload, cleanup after failure and stale completion.

Exercise real filesystem/command integration where the plugin owns that behavior.

Run project plugin test/typecheck/build commands and relevant host consumers.

Before returning

Skills in scope

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.