Plugin development

# Customize PI WEB with local UI plugins.

Plugins are trusted browser-side ES modules. They can add actions, workspace panels, and compact workspace labels to the PI WEB UI.

## What can be extended

Plugins can add small, focused UI extensions to PI WEB:

- Action palette commands for custom workflows.
- Workspace tools and panels next to Files, Git, and Terminal.
- Workspace labels in the workspace list, header, and status bar.
- Static assets served from the plugin folder.
- Browser-side integrations using PI WEB HTTP/WebSocket APIs.

Plugins cannot extend the session daemon or add server-side hooks. They run in the browser UI only.

The plugin API is intentionally limited and actively developed. Feedback is appreciated: if an extension point is missing, unclear, or awkward, please open a GitHub issue.

## What to ask AI to build

You do not need to hand-code plugins. Give an AI agent a clear goal, the workspace/project facts it should use, and the PI WEB plugin rules.

- Show a workspace badge from a repo file, environment file, branch name, container, or dev URL.
- Add a workspace panel that summarizes project-specific health, commands, links, or runbooks.
- Add action-palette commands for common project workflows or prompts.
- Add links to local services, preview deployments, dashboards, CI, logs, or docs.

Prompt: create a plugin

    Build a PI WEB plugin for this project.
    Goal: <describe the UI behavior>.
    Before coding, read the PI WEB plugin docs:
    https://pi-web.dev/plugins.html
    Full API reference:
    https://pi-web.dev/plugins.md
    Create it as a local plugin under ~/.pi-web/plugins/<plugin-id>.
    Use the appropriate extension points from the docs.
    Validate by checking /pi-web-plugins/manifest.json and explain how to reload/debug it.
    Do not modify PI WEB itself.

Prompt: improve a plugin

    Improve the PI WEB plugin at <path>.
    Before coding, read the PI WEB plugin docs:
    https://pi-web.dev/plugins.html
    Full API reference:
    https://pi-web.dev/plugins.md
    Keep the plugin compatible with the documented v1 API.
    After editing, check the manifest endpoint and browser-console failure cases.

## Canonical example

PI WEB ships a real bundled Info plugin. It is intentionally small while still using all core contribution types: one action, one workspace label, and one workspace panel.

Bundled PI WEB plugins are developed as TypeScript in the repository, while their package metadata points at the built JavaScript ES modules that the browser loads. `npm run dev:web` watches and rebuilds bundled plugin TS into `dist/pi-web-plugins/` during development, and `npm run build` emits JS before release packaging.

- `pi-web-plugins/info/package.json` shows the required metadata shape.
- `pi-web-plugins/info/pi-web-plugin.ts` shows the TypeScript source shape.
- `dist/pi-web-plugins/info/pi-web-plugin.js` is the built browser module in a checkout.

Read it on GitHub: pi-web-plugins/info. If you copy it, choose a new plugin id so it does not conflict with the bundled `info` plugin.

The bundled `pi-web` status plugin demonstrates dynamic `visible` and `badge` callbacks for tabs that only appear when the host has status messages or needs extra install visibility.

## Production usage

Local plugins work with the production npm/systemd install. Put each plugin under `~/.pi-web/plugins/<plugin-id>/`, or symlink it there while developing. No PI WEB rebuild or session-daemon restart is required.

If `PI_WEB_DATA_DIR` is set, use `$PI_WEB_DATA_DIR/plugins` instead of `~/.pi-web/plugins`.
Install a local plugin folder

    $ mkdir -p ~/.pi-web/plugins
    $ ln -s /path/to/plugin-folder ~/.pi-web/plugins/plugin-id

## AI-friendly docs

The full plugin reference is available as Markdown for AI agents to read, fetch, and follow: plugins.md.

If you want to understand the API yourself, ask an agent to read that file and explain the relevant extension points for the plugin you want. The Markdown reference also marks which context fields are stable and which PI WEB internals should be avoided unless necessary.

## Develop and debug

- Keep the source folder outside `~/.pi-web/plugins` and symlink it in.
- After edits, reload or hard-reload the browser tab.
- Check discovery with the manifest endpoint.
- Check the browser console if a plugin fails to import or activate.

Check discovered plugins

    $ curl http://127.0.0.1:8504/pi-web-plugins/manifest.json

For all contribution types and package metadata, read the Plugin API reference.

## Trust model

Plugins are not sandboxed. They run as JavaScript in the browser, can call PI WEB APIs available to the current session, and can render arbitrary UI. Install only plugins you trust.

Plugins do not run inside the session daemon and do not provide server-side hooks.