Plugin System¶
microharness supports self-contained plugin bundles (plugin.json) alongside single-file ~/.microharness/tools/*.py plugins and Python ToolProvider / CodeModeHelperProvider implementations—while keeping core strictly zero-dependency (dependencies = [] in pyproject.toml).
Discovery Locations & Precedence¶
Plugins are discovered in the following order (lowest to highest priority; later entries with the same plugin ID shadow earlier ones):
- Bundled first-party plugins (
plugins/<name>/) — e.g.,plugins/mcp/(scope = "bundled"). - Python packaging entry points (
microharness.plugins) — optional third-party packages discovered viaimportlib.metadata.entry_points(group="microharness.plugins")only whenenable_entrypoint_plugins: trueis set (default: falseincore/defaults.json). - Global user plugins (
~/.microharness/plugins/<name>/) — trusted automatically across all projects (scope = "global"). - Preset-bundled plugins (
<preset>/plugins/<name>/) — inherits the active preset's scope (global,project, orpath). - Project-local plugins (
.microharness/plugins/<name>/) — executable code (provider,tools/, commandhooks,mcp_servers,runtime) requires--trust-project-toolsor"trust_project_tools": truein~/.microharness/config.json.
CLI & Interactive Lifecycle¶
Manage installed plugins from the terminal or inside any interactive/TUI session:
# Install from a local directory or git repository
uv run microharness plugin install ./my-plugin
uv run microharness plugin install https://github.com/org/my-plugin.git --ref v1.0.0
uv run microharness plugin install ./repo-plugin --project # install into .microharness/plugins/
# Inspect discovered plugins (bundled, global, project)
uv run microharness plugin list
uv run microharness plugin list --json
# Enable or disable a plugin (recorded in plugins.json without modifying config.json comments)
uv run microharness plugin disable mcp
uv run microharness plugin enable mcp
# Update installed plugins from their recorded git/local source
uv run microharness plugin update my-plugin
uv run microharness plugin update --all
# Remove an installed plugin
uv run microharness plugin remove my-plugin
Inside the interactive chat or TUI, /plugin (or /plugins) supports the same lifecycle subcommands:
/pluginor/plugin list/plugin install <git-url|local-path> [--name NAME] [--ref REF] [--project] [--force]/plugin enable <name> [--project]//plugin disable <name> [--project]/plugin update <name|--all> [--project]/plugin remove <name> [--project]
Directory Layout & plugin.json Manifest¶
~/.microharness/plugins/my-plugin/
├── plugin.json # Required manifest (JSON or JSONC with // and # comments)
├── defaults.json # Optional plugin-owned declarative defaults
├── provider.py # Optional ToolProvider / PluginContribution factory
├── tools/ # Optional *.py tool modules
├── skills/ # Optional <name>/SKILL.md or *.md skills
├── subagents/ # Optional *.md or <name>/AGENT.md subagents (agents/ also accepted)
└── commands/ # Optional *.md custom slash commands
Example plugin.json:
{
"name": "my-plugin",
"version": "0.1.0",
"description": "Custom bundle with provider, skills, hooks, and CLI flags",
"defaults": "defaults.json",
"provider": "provider.py:create_plugin",
"activate_on_config_keys": ["my_plugin_enabled"],
"frontmatter_keys": {
"my_plugin_mode": "str"
},
"cli": [
{
"flags": ["--my-plugin-mode"],
"dest": "my_plugin_mode",
"choices": ["fast", "deep"],
"default": null,
"config_key": "my_plugin_mode",
"group": "plugin",
"help": "Select my-plugin mode"
}
],
"hooks": [
{
"event": "post_tool",
"name": "my_plugin_audit",
"command": "echo Tool finished",
"matcher": "write_file"
}
],
"mcp_servers": {}
}
Key Manifest Fields¶
| Field | Purpose |
|---|---|
name / id |
Lowercase plugin identifier ([a-z0-9][a-z0-9._-]*) |
defaults |
Inline object or relative path (e.g. "defaults.json") for plugin-owned defaults |
provider |
Module/file factory ("provider.py:create_plugin" or "pkg.mod:fn") receiving PluginContext and returning a ToolProvider or PluginContribution |
activate_on_config_keys |
Optional list of config keys; when set, the plugin's Python module stays unimported unless one of those keys is configured |
cli |
Declarative argparse options contributed by the plugin (colliding built-in flags are skipped with a warning) |
frontmatter_keys |
Optional agent.md frontmatter keys ("bool", "str", "int", "float") recognized by core/presets.py |
tools, skills, subagents, commands |
Optional relative directory overrides (false disables discovery for that folder) |
hooks, mcp_servers |
Optional declarative hooks and MCP server entries contributed by the plugin |
defer, defer_tools |
Opt into deferred tool loading ("defer": true or "defer_tools": ["..."], also configurable under plugins.<id>.defer in config.json); pairs with tool_search and code_mode (tools.search()) |
dependencies, runtime |
Optional isolated subprocess runtime (uv, python, npx, stdio) |
Isolated Plugin Dependencies (uv / npx / stdio)¶
Plugins that require third-party packages can declare dependencies and runtime in plugin.json without modifying microharness's core pyproject.toml:
{
"name": "isolated-service",
"version": "0.1.0",
"description": "Runs in an isolated uv environment over stdio JSON-RPC 2.0",
"dependencies": ["httpx>=0.27"],
"runtime": {
"type": "uv",
"python": ">=3.11",
"args": ["server.py"],
"protocol": "jsonrpc-stdio",
"env": {
"SERVICE_API_KEY": "env:SERVICE_API_KEY"
},
"allow_in_sandbox": false,
"requires_network": true,
"sandbox": {
"mode": "auto",
"filesystem": "workspace-ro",
"network": "allowlist",
"allowed_hosts": ["api.example.com"]
}
}
}
protocol: "jsonrpc-stdio":core/plugins.pylaunches the process viaStdioPluginToolProvider, performsinitializeandtools/listover newline-delimited JSON-RPC 2.0, exposes each returned tool (annotations.readOnlyHintenforced inread-onlymode), and shuts down the subprocess onteardown().protocol: "mcp-stdio": Contributes the resolved command (withplugin.pathgranted read-only inside OS sandboxes and stripped hostos.environ) as a stdio MCP server handled byplugins/mcp/.sandbox: Optional granular sandbox policy (mode,filesystem,read_paths,write_paths,network,allowed_hosts,env_passthrough,inherit_host_env) enforced viacore/sandbox.pyunder--sandbox/--docker.type: "uv": Usesuv run --no-project --with <dep>...(or a pre-created<plugin>/.venvviaprepare_plugin_venv), keeping dependencies isolated per plugin.
Contributing CodeModeHelpers (code_mode)¶
A ToolProvider can implement CodeModeHelperProvider.get_code_mode_helpers() (core/protocols.py) to expose Python helper clients inside code_mode scripts (as plugins/mcp/ does for mcp.search(...) and mcp.call(...)):
from core.code_mode import CodeModeHelper
class MyProvider:
name = "my-plugin"
...
def get_code_mode_helpers(self):
return [
CodeModeHelper(
name="myclient",
code="class _Client:\n def ping(self): return tools.call('my_ping')\nmyclient = _Client()\n",
description="`myclient.ping()`",
)
]
Enable standalone code_mode via --code-mode or Harness(..., enable_code_mode=True).
Bundled First-Party Plugins¶
microharness ships two zero-dependency bundled plugins under plugins/:
plugins/mcp/ — Model Context Protocol¶
Lazy-loaded MCP client (stdio, Streamable HTTP, and /sse) plus the mcp CodeModeHelper. Only activates when mcp_servers is configured. See MCP & Python Code Mode.
plugins/background_shell/ — Background Shell Process Management¶
Lifecycle-managed background shell processes (BackgroundShellToolProvider) so agents can start local dev servers, watchers, or daemons, wait for readiness output, inspect tail logs, send stdin, and clean up process groups deterministically on exit.
Tools & code_mode Helper¶
| Tool | Read-Only? | Purpose | Key Parameters |
|---|---|---|---|
bg_start |
No (modifies_files=True) |
Start a background process inside the workspace and return its handle | command (required), cwd, name, env, wait_seconds |
bg_status |
Yes (parallel_safe=True) |
Inspect status and tail combined stdout/stderr logs, or list all tracked handles | handle (optional), tail_lines, wait_seconds, wait_for |
bg_write |
No (modifies_files=True) |
Write bounded text to a running process's stdin |
handle (required), input, eof |
bg_kill |
No (modifies_files=True) |
Terminate a process and its process group (SIGTERM → grace → SIGKILL) |
handle (required), force, timeout |
When code_mode is enabled, bg is also exposed as a Python helper (bg.start(...), bg.status(...), bg.list(), bg.write(...), bg.kill(...)).
Configuration & CLI Flags¶
- CLI flags:
--background-shell/--no-background-shell agent.mdfrontmatter / config:"enable_background_shell": true(defaulttrueinplugins/background_shell/defaults.json; also configurable underplugins.background_shellinconfig.json)- Disable globally:
uv run microharness plugin disable background_shell(or--no-background-shellper run) - Operational defaults (
plugins/background_shell/defaults.json): - Concurrency & startup:
bg_max_processes: 8,bg_max_retained_processes: 32,bg_startup_wait_seconds: 0.1,bg_default_wait_for_seconds: 5.0,bg_max_wait_seconds: 30.0 - Bounded logs & input:
bg_ring_buffer_lines: 500,bg_max_line_chars: 4096,bg_max_spill_bytes: 5242880(logs_dir/bg_<handle>.logspillover),bg_default_tail_lines: 100,bg_max_tail_lines: 500,bg_max_input_bytes: 65536 - Teardown:
bg_grace_timeout: 3.0,bg_max_grace_timeout: 30.0,bg_docker_cleanup_timeout: 5.0 - Sandbox policy (
background_shell_sandbox/plugins.background_shell.sandbox):bg_sandbox_mode: "auto",bg_sandbox_filesystem: "workspace",bg_sandbox_network: "full",bg_sandbox_inherit_host_env: false(bg_host_safe_env_keysstrips host secrets by default; sandbox policy overrides in project/preset configs require--trust-project-toolsor global preset scope)
Security & Cleanup Guarantees¶
read-only&askmodes:bg_start,bg_write, andbg_killare denied inReadOnlyEnvironmentand prompt viaGuardedEnvironmentinaskmode;bg_statusstays read-only.- Workspace & Container Isolation:
cwdis trapped strictly inside the workspace (/workspaceunder--docker), OS sandboxes (sandbox-exec/bwrap) wrap background processes under--sandbox, and--dockerlaunches/signals processes inside the active container (DockerEnvironment). - Zero Orphaned Processes: Host processes run in isolated sessions/process groups (
SIGTERM→bg_grace_timeout→SIGKILL), andToolProvider.teardown()/Environment.register_teardown_hook()automatically clean up all live background processes onHarnessexit, errors, timeouts, or cancellation.