v0.2.0 — Worker pre/post-execute JS hooks
Worker pre/post-execute JS hooks 🪝
Workers can now carry two optional JavaScript hooks that run in MCPlexer's existing code-mode (goja) sandbox, around the model loop:
pre_execute_script— runs before any model/CLI spend and can block the run.throwor callabort(reason)to stop it; return cleanly to proceed. Use it to hit an endpoint, check a flag, or read a condition and decide whether the worker should run at all. A blocked run costs zero tokens.post_execute_script— runs after output is produced and can reject it (throw on a successful run), which suppresses emission to every output channel.
This lets an agent provisioning a worker attach a gate like "only run if https://…/gate says go" or "don't publish output shorter than N chars" — entirely declaratively.
How it works
- Hooks run through the worker's own
mcpx__execute_codepath, so they inherit that worker's tool allowlist, capability profile, and audit trail — no new sandbox or privilege surface. (There's no JSfetch; reach an HTTP endpoint via an allowed downstream tool, e.g.fetch.fetch({url}).) - A generated preamble binds a
hookcontext object —{phase, worker, run, params}(post addsrun.status/output/error/tokens/cost) — plusabort(reason)/proceed()helpers. - New terminal run status
blocked— deliberately notfailure, so an intentional gate never trips the consecutive-failure auto-pause. - Fail-closed: a hook that throws, times out, or fails to dispatch blocks the run.
- Scripts are validated at write time with
codemode.Preflight(syntax + noeval/Function/import/require) and a 64 KB cap.
Surfaces
- New
workers.pre_execute_script/post_execute_scriptcolumns (migration 125 + idempotent boot invariant). - Exposed on
create_worker,update_worker, andmcpx__delegate_worker. - Web editor: Tools → Execute hooks; read-only config view;
blockedstatus badge.
Tested
- Go unit + integration tests (hook engine, validation, store round-trip).
- Live end-to-end against the built daemon:
gate=no→blocked(zero spend);gate=yes→success; post-hook veto flips success →blocked; malformed hook JS rejected at create.
Artifact
mcplexer-v0.2.0-darwin-arm64.tar.gz — macOS (Apple Silicon) build, web UI embedded. Build from source with task build for other platforms.
🤖 Generated with Claude Code