Skip to content

v0.2.0 — Worker pre/post-execute JS hooks

Choose a tag to compare

@revitteth revitteth released this 29 Jun 20:22
v0.2.0
b2c571e

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. throw or call abort(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_code path, so they inherit that worker's tool allowlist, capability profile, and audit trail — no new sandbox or privilege surface. (There's no JS fetch; reach an HTTP endpoint via an allowed downstream tool, e.g. fetch.fetch({url}).)
  • A generated preamble binds a hook context object — {phase, worker, run, params} (post adds run.status/output/error/tokens/cost) — plus abort(reason) / proceed() helpers.
  • New terminal run status blocked — deliberately not failure, 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 + no eval/Function/import/require) and a 64 KB cap.

Surfaces

  • New workers.pre_execute_script / post_execute_script columns (migration 125 + idempotent boot invariant).
  • Exposed on create_worker, update_worker, and mcpx__delegate_worker.
  • Web editor: Tools → Execute hooks; read-only config view; blocked status badge.

Tested

  • Go unit + integration tests (hook engine, validation, store round-trip).
  • Live end-to-end against the built daemon: gate=noblocked (zero spend); gate=yessuccess; 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