FN-5844: add plugin dev loop and external authoring docs

Add a local plugin development loop plus publishable external plugin guidance.

- add `fn plugin dev` routing and implementation with supervised build, install, and hot-reload behavior
- export plugin loader/store helpers and add CLI tests for dev flow, pack shape validation, and scaffold docs coverage
- document external plugin authoring, update CLI/plugin authoring docs, and add a patch changeset for `@runfusion/fusion`

Files changed:
 .changeset/fn-5844-external-plugin-authoring.md    |   5 +
 docs/PLUGIN_AUTHORING.md                           |  10 +-
 docs/cli-reference.md                              |   3 +-
 docs/plugins/external-authoring.md                 | 114 +++++++++++
 packages/cli/src/__tests__/bin.test.ts             |  16 +-
 packages/cli/src/__tests__/plugin-dev.test.ts      | 138 ++++++++++++++
 .../cli/src/__tests__/plugin-pack-shape.test.ts    |  94 +++++++++
 packages/cli/src/__tests__/plugin-scaffold.test.ts |   3 +
 packages/cli/src/bin.ts                            |  16 +-
 packages/cli/src/commands/plugin-dev.ts            | 212 +++++++++++++++++++++
 packages/cli/src/commands/plugin-scaffold.ts       |   6 +-
 packages/cli/src/commands/plugin.ts                |   6 +-
 12 files changed, 613 insertions(+), 10 deletions(-)

Fusion-Task-Id: FN-5844
Fusion-Task-Lineage: 80afa0a0-225c-486d-901a-909d14e7b056
This commit is contained in:
gsxdsm
2026-06-01 19:40:14 -07:00
parent b09bbbce9c
commit 0a418e6875
12 changed files with 613 additions and 10 deletions

View File

@@ -5,6 +5,7 @@ A comprehensive guide to creating Fusion plugins that extend the task board with
## Table of Contents
1. [Getting Started](#1-getting-started)
- [External authoring guide](./plugins/external-authoring.md)
2. [Plugin Manifest Reference](#2-plugin-manifest-reference)
3. [Plugin Settings Schema](#3-plugin-settings-schema)
4. [Available Hooks and Signatures](#4-available-hooks-and-signatures)
@@ -44,15 +45,18 @@ Fusion plugins extend the task board with custom functionality:
### Quick Start
Create a new plugin using the scaffold command:
External authors should use the standalone scaffold and dev loop (see the [External Plugin Authoring guide](./plugins/external-authoring.md)):
```bash
fn plugin create my-first-plugin
fn plugin new my-first-plugin
cd my-first-plugin
pnpm install
fn plugin dev .
pnpm test
```
The legacy `fn plugin create` scaffold remains available for workspace-bound examples.
### Optional AI Security Scan (Opt-in)
Plugin installs now support an opt-in `aiScanOnLoad` flag. When enabled, Fusion runs an AI security review before loading plugin code.
@@ -1176,6 +1180,8 @@ This keeps regressions durable while preserving clear ownership boundaries acros
## 13. Publishing Plugins
For end-to-end standalone packaging, `pnpm pack`, and installing on another machine, follow the [External Plugin Authoring guide](./plugins/external-authoring.md).
### Package Requirements
```json

View File

@@ -987,9 +987,10 @@ fn plugin enable <id>
fn plugin disable <id>
fn plugin create <name>
fn plugin new <name> [--output <dir>] [--scope <scope>]
fn plugin dev <path> [--once] [--ai-scan]
```
Subcommands: `list|ls`, `install`, `rescan`, `trust`, `untrust`, `verify`, `uninstall`, `enable`, `disable`, `create`, `new`.
Subcommands: `list|ls`, `install`, `rescan`, `trust`, `untrust`, `verify`, `uninstall`, `enable`, `disable`, `create`, `new`, `dev`.
Scope semantics:
- `fn plugin install` / `fn plugin uninstall` are **global** operations

View File

@@ -0,0 +1,114 @@
# External Plugin Authoring
This guide is for plugin authors using an installed `@runfusion/fusion` CLI. You do not need access to the Fusion monorepo.
## Prerequisites
- Node.js 18+
- `pnpm` (or use the equivalent `npm` commands where noted)
- An installed Fusion CLI available as `fn`
## 1. Scaffold a standalone plugin
```bash
fn plugin new my-plugin
cd my-plugin
pnpm install
```
The scaffold creates a standalone package named `fusion-plugin-my-plugin`. It depends on the published `@runfusion/fusion` package and imports SDK helpers from `@runfusion/fusion/plugin-sdk`; it must not contain private `@fusion/*` imports or `workspace:*` dependencies.
## 2. Develop locally with hot reload
Start Fusion locally, then run the plugin dev loop from the plugin directory:
```bash
fn plugin dev .
```
`fn plugin dev .`:
1. Runs the plugin build script (`pnpm build`, with `npm run build` fallback).
2. Resolves the compiled JavaScript entry from `package.json` exports/main or `dist/index.js`.
3. Reads and validates the root `manifest.json`.
4. Installs and enables the plugin into the local Fusion plugin store.
5. Watches `src/` and, on save, rebuilds and hot-reloads with the Fusion plugin loader.
For a single CI-safe build/install/load pass without a watcher, use:
```bash
fn plugin dev . --once
```
You can also run the build yourself:
```bash
pnpm build
```
Troubleshooting: plugin entrypoints must be compiled JavaScript. `fn plugin install` and `fn plugin dev` reject `.ts` source entrypoints, so run the build before installing if you are not using the dev loop.
## 3. Test
```bash
pnpm test
```
If you prefer npm for a scaffold that supports it:
```bash
npm test
```
## 4. Package
Build first, then create an npm tarball:
```bash
pnpm build
pnpm pack
```
For `my-plugin` version `0.1.0`, the tarball is named like:
```text
fusion-plugin-my-plugin-0.1.0.tgz
```
The scaffolded package publishes only the files declared in `package.json` (`dist`, `manifest.json`, and package metadata) and exposes the plugin through:
```json
{
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.js"
}
}
}
```
Before sharing the tarball, confirm the artifact does not include private monorepo-only strings:
- no `@fusion/*` imports or dependencies
- no `workspace:*` dependency ranges
- SDK imports come from `@runfusion/fusion/plugin-sdk`
## 5. Install elsewhere
On another machine with Fusion installed, extract or install the tarball, then point Fusion at the extracted plugin directory:
```bash
tar -xzf fusion-plugin-my-plugin-0.1.0.tgz
fn plugin install ./package
fn plugin enable fusion-plugin-my-plugin
```
If the plugin directory is already available, install it directly:
```bash
fn plugin install /path/to/fusion-plugin-my-plugin
fn plugin enable fusion-plugin-my-plugin
```
Use `fn plugin list` to confirm the plugin is installed and enabled for the current project.