# Plugin Development This is the consolidated reference for **creating** or **editing** a plugin in MulmoClaude. Read this when you're about to touch `packages/plugins/-plugin/` or `src/plugins//`. For day-to-day work that doesn't touch a plugin's surface, the load-bearing rules in [`CLAUDE.md`](../CLAUDE.md) are enough. Related docs: - [`docs/developer.md`](developer.md) — full developer guide (envs / scripts / process map / workspace layout) - [`docs/plugin-runtime.md`](plugin-runtime.md) — runtime / npm-package plugin internals (the `/api/plugins/runtime/:pkg/*` dispatch surface, OAuth callback flow, role gating) - [`CLAUDE.md`](../CLAUDE.md) — section "Package dependency direction" — the import-direction rule that applies to **every** code edit, plugin or not (load-bearing across all sessions, not duplicated here) There are two flavours of plugin in this repo: | Kind | Lives at | Distribution | Examples | |---|---|---|---| | **Built-in plugin** | `src/plugins//` | bundled into the host's Vite client + Express server | wiki, news, presentMulmoScript | | **Runtime plugin** | `packages/plugins/-plugin/` | standalone `@mulmoclaude/-plugin` npm package, dispatched via `/api/plugins/runtime/:pkg`, gated by roles | bookmarks, chart, collection, debug, edgar, email, form, html, markdown, recipe-book, spotify, todo, x | **Default to runtime plugin** for per-feature integrations (Spotify / GitHub / Apple Music / weather / bookmarks / …). Built-in is appropriate only for surfaces deeply tied to the host shell (wiki, news, the `presentMulmoScript` canvas). --- ## Plugin-vs-host boundary (always apply) Per-feature integrations live in `packages/plugins/-plugin/`. Host code (`server/`, `src/plugins/`, `src/config/`) only gets **generic infrastructure that benefits multiple plugins** — never provider-specific code. Examples of generic host infra: - the `/api/plugins/runtime/:pkg/dispatch` route - the asset-mount route - the `/api/plugins/runtime/:pkg/oauth/callback` route (#1162) A new "Spotify route" or "GitHub route" in `server/api/routes/` is a smell — re-think whether the work belongs in the plugin package and whether the host's infra needs a *generic* extension instead. --- ## Built-in plugin path ### Plugin owns its identity Each built-in plugin declares its `toolName`, `apiRoutes`, `workspaceDirs`, and `staticChannels` in its own `src/plugins//meta.ts`. Host aggregators (`API_ROUTES`, `TOOL_NAMES`, `WORKSPACE_DIRS`, `PUBSUB_CHANNELS`) auto-merge those contributions via `defineHostAggregate` — host code holds zero plugin-specific literals. ### The 6 plugin-local files + 3 host barrels Adding a built-in plugin touches: **Plugin-local (6 files under `src/plugins//`):** - `meta.ts` — `definePluginMeta({ toolName, apiRoutesKey?, apiRoutes?, workspaceDirs?, staticChannels? })` - `definition.ts` — MCP `ToolDefinition`; derive `TOOL_NAME = META.toolName`, endpoint types from `typeof META.apiRoutes` - `index.ts` — `PluginRegistration` (View / Preview wrapped via `wrapWithScope(scope, …)`, executor calls `pluginEndpoints(scope)`) - `View.vue` / `Preview.vue` — Vue surfaces; call `useRuntime()` from `gui-chat-protocol/vue` for the typed `endpoints` map **Host barrels (3 files):** - `src/plugins/metas.ts` — append the META to `BUILT_IN_PLUGIN_METAS` - `src/plugins/index.ts` — append the registration to `BUILT_IN_PLUGINS` - `src/plugins/server.ts` — append `{ def, endpoint }` to `BUILT_IN_SERVER_BINDINGS` (skip for GUI-only plugins like wiki) **Optional endpoint surface:** - `server/api/routes/.ts` — Express route handlers (only when the plugin owns endpoints) - `src/main.ts` — entry in the host endpoint registry passed to `installHostContext({ endpoints })` Adding to a Role's `availablePlugins` (`src/config/roles.ts`) is separate — roles gate which plugins each chat sees, independent of plugin registration. ### Standalone routes + inline previews must scope Standalone routes (`/todos`, `/calendar`, …) and inline file previews (`FileContentRenderer` rendering `data/todos/todos.json`) must wrap the plugin component with `` so descendant `useRuntime()` calls resolve. The plugin registry's `wrapWithScope` already covers chat-mounted variants. --- ## Runtime plugin path Use the scaffold: ```bash npx create-mulmoclaude-plugin ``` That stamps `packages/plugins/-plugin/` with a working `package.json` + Vite + TypeScript config + ESLint config. From there, see [`docs/plugin-runtime.md`](plugin-runtime.md) for the dispatch / runtime protocol details. ### Plugin scaffold sync (`packages/create-mulmoclaude-plugin`) The scaffold CLI embeds `package.json` + `vite.config.ts` + `tsconfig.json` + ESLint config as **string literals** in `packages/create-mulmoclaude-plugin/src/template.ts`. Newly-generated plugins inherit those literals verbatim, so they DO NOT pick up version bumps you make to the in-tree plugins. **When you bump a build-toolchain dep** (`vite` / `typescript` / `vite-plugin-dts` / `@vitejs/plugin-vue` / `vue`) or change the build-config shape (e.g. dropping `rollupTypes: true` for a TS-major bump), apply the same change to `packages/create-mulmoclaude-plugin/src/template.ts` in the **same PR**: 1. Update the `PACKAGE_JSON` template's `devDependencies` caret ranges to match `packages/plugins/bookmarks-plugin/package.json` (the canonical reference). 2. If the build-config shape changed, mirror it into `VITE_CONFIG` (the multi-line string just below). 3. Run `yarn workspace create-mulmoclaude-plugin run build` to regenerate the CLI's own dist. 4. Optionally bump the CLI's own `version` and re-publish if external users will fetch via `npx`. Step 1 is asserted by `packages/create-mulmoclaude-plugin/test/test_toolchain_sync.ts`: every `bookmarks-plugin` devDependency must appear in the template at the same range (`gui-chat-protocol` is exempt while the template stays on the 1.x protocol), so a bump or a new dep made on one side only turns `yarn test` red. Template-only devDependencies (the ESLint set) are allowed. If you forget step 2, generated plugins ship with stale toolchains and may hit the same issue you just fixed in the in-tree plugin (e.g. empty `.d.ts` from api-extractor + TS 6). **The same applies to how strictly a plugin is checked**, and that half is easier to miss because nothing about a generated plugin looks broken: - `TSCONFIG` must carry `noUncheckedIndexedAccess` + `exactOptionalPropertyTypes`. `strict: true` does not include either, so a template with only `strict` hands every new plugin a weaker checker than any in-tree one. It is byte-identical to `bookmarks-plugin/tsconfig.json` — diff against that. - `PACKAGE_JSON`'s `typecheck` must be `vue-tsc`, not `tsc`, for as long as the template ships `src/View.vue`. `tsc` parses no `.vue` file whatsoever: it reports zero for a template and a `