From 2e3b6990c901c3fd9f2d663add19246e5b433b86 Mon Sep 17 00:00:00 2001 From: repo-worker-tmp-code-b Date: Tue, 17 Nov 2026 03:10:46 -0600 Subject: [PATCH] =?UTF-8?q?fix(mcpx):=20settings=20env-contract=20currency?= =?UTF-8?q?=20=E2=80=94=20compendium=20manifest,=20environment=20doc,=20su?= =?UTF-8?q?pervisor=20owner=20PID=20setter=20(#3016)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkgs/mcpx/docs/compendium.manifest.json | 14 +++ pkgs/mcpx/docs/environment.md | 111 +++++++++--------- pkgs/mcpx/internal/settings/scriptenv.go | 15 +++ pkgs/mcpx/internal/settings/scriptenv_test.go | 1 + 4 files changed, 86 insertions(+), 55 deletions(-) diff --git a/pkgs/mcpx/docs/compendium.manifest.json b/pkgs/mcpx/docs/compendium.manifest.json index d295076863..139be934b9 100644 --- a/pkgs/mcpx/docs/compendium.manifest.json +++ b/pkgs/mcpx/docs/compendium.manifest.json @@ -95,6 +95,20 @@ "lines": 306, "note": "lootbox audit, why Go, what was built (historical; keeps its text)" }, + { + "path": "agents-docs/README.md", + "chapter": null, + "role": "not-compendium", + "lines": 19, + "note": "explains the hand-written agent-twin override sources (#1947); the directory is twin source material for docs-twins emit, not a book chapter" + }, + { + "path": "agents-docs/index.md", + "chapter": null, + "role": "not-compendium", + "lines": 65, + "note": "hand-written agent twin override for the book home page (#1947); it surfaces as the home page twin, not as its own chapter" + }, { "path": "daemon/README.md", "chapter": null, diff --git a/pkgs/mcpx/docs/environment.md b/pkgs/mcpx/docs/environment.md index eb3d20fe1b..ac19610280 100644 --- a/pkgs/mcpx/docs/environment.md +++ b/pkgs/mcpx/docs/environment.md @@ -90,60 +90,61 @@ and read by name for that reason. -| variable | set by | when | what it is | read by | -| --------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `MCPX_SESSION` | `mcpx exec` / `mcpx run`; the exec service (`/v1/exec`, `mcpx_exec`); an event consumer | always | the session key this run's tool calls are leased under: --session, else MCPX_SESSION_ID, else one minted for the run | the generated client, which sends it with every call | -| `MCPX_SESSION_ID` | `mcpx exec` / `mcpx run`; the exec service (`/v1/exec`, `mcpx_exec`); an event consumer; the opencode plugin; the plugin loader, for a discovered plugin | the CLI passes through the value it was given, which may be empty; the plugin sets it at every plugin.env level | the session the host assigned. Unlike MCPX_SESSION it survives from one command to the next, so it is what session-scoped servers key on | `mcpx` run inside the script or shell, as its session when --session is not given | -| `MCPX_PARENT_SESSION_ID` | `mcpx exec` / `mcpx run`; an event consumer; the opencode plugin | the CLI passes through what it was given; the daemon passes the caller's parent session into a script run's environment; the plugin at plugin.env=full, when there is a parent | the session that spawned this one, so a parent agent and its subagents can share a server | `mcpx` run inside the script or shell, and the generated client for parent-session scoping | -| `MCPX_EPHEMERAL` | `mcpx exec` / `mcpx run`; the exec service (`/v1/exec`, `mcpx_exec`) | always | 1 when the session key was minted for this run alone, so its instances may be stopped as soon as it ends | the generated client | -| `MCPX_RUN` | `mcpx exec` / `mcpx run`; the exec service (`/v1/exec`, `mcpx_exec`) | always | this execution's run id, which groups the artifacts it produces | the generated client, when storing an artifact | -| `MCPX_INPUT` | `mcpx exec` / `mcpx run` | mcpx exec and mcpx run, locally and with --remote; not when mcpx serve collects the output | report: nothing in this run can answer a server's question mid-call, so a call that asks one exits 75 with the question instead of waiting for it to expire | the generated client, sent as X-Mcpx-Input | -| `MCPX_HOOK_NAME` | the declared-hook runner, for a hook it runs | always | the declared name of the hook being run | the hook itself | -| `MCPX_HOOK_PHASE` | the declared-hook runner, for a hook it runs; the exec service (`/v1/exec`, `mcpx_exec`) | always | the hook's phase; always observe for config-declared hooks, the exec hook's phase (pre, post, onError, onSuccess) for a per-call exec hook | the hook itself | -| `MCPX_HOOK_POINT` | the exec service (`/v1/exec`, `mcpx_exec`) | always | the point the hook is attached to; script for per-call exec hooks in this version | the hook itself | -| `MCPX_HOOK_ERROR` | the exec service (`/v1/exec`, `mcpx_exec`) | only for a hook running because the script failed; truncated to 1024 bytes | the error the hook is running for, in one line; the full hook context is JSON on stdin | the hook itself | -| `MCPX_HOOK_EVENT_KIND` | the declared-hook runner, for a hook it runs | always | the kind of the event the hook is running for; the full event is JSON on stdin | the hook itself | -| `MCPX_HOOK_EVENT_SEQ` | the declared-hook runner, for a hook it runs | always | the event's sequence number on the daemon's bus | the hook itself | -| `MCPX_HOOK_EVENT_SERVER` | the declared-hook runner, for a hook it runs | empty when the event names no server | the server the event is about | the hook itself | -| `MCPX_HOOK_EVENT_SESSION` | the declared-hook runner, for a hook it runs | empty when the event belongs to no session | the session the event belongs to | the hook itself | -| `MCPX_HOOK_EVENT_URI` | the declared-hook runner, for a hook it runs | empty when the event names no resource | the resource URI the event is about | the hook itself | -| `MCPX_ENDPOINT` | `mcpx exec` / `mcpx run`; the exec service (`/v1/exec`, `mcpx_exec`); an event consumer | always | the daemon's HTTP endpoint | the generated client; the plugin as a fallback for MCPX_DAEMON_ENDPOINT | -| `MCPX_SOCKET` | `mcpx exec` / `mcpx run`; the exec service (`/v1/exec`, `mcpx_exec`); the plugin loader, for a discovered plugin | empty when the daemon is remote, since its socket is not reachable from here | the daemon's unix socket, which is faster than the endpoint. Also where a daemon binds and a client dials, for anyone who sets it by hand | the generated client, `mcpx` run inside the script or shell, the plugin | -| `MCPX_TRANSPORT_BEARER_TOKEN` | `mcpx exec` / `mcpx run`; the exec service (`/v1/exec`, `mcpx_exec`); an event consumer | only when transport.bearerToken is configured | the daemon's bearer token, handed to the script so the generated client can authenticate to a daemon that requires it (#1975); the token itself stays out of the generated code | the generated client, `mcpx` run inside the script or shell, the plugin; also the setting `transport.bearerToken` | -| `MCPX_SETTINGS` | `mcpx exec` / `mcpx run`; the exec service (`/v1/exec`, `mcpx_exec`) | only when the caller sent call settings with the run (for example a requested pool.callTimeout) | the call-settings header for this run, carried into the script so the generated client forwards the caller's per-call requests on the calls it makes on the script's behalf | the generated client, which sends it as the x-mcpx-settings header | -| `MCPX_ARTIFACTS_LOCAL` | `mcpx exec` / `mcpx run`; the exec service (`/v1/exec`, `mcpx_exec`) | always | 1 when the daemon shares this filesystem, so artifact({path}) may hand over a path instead of the bytes | the generated client | -| `MCPX_CWD` | `mcpx exec` / `mcpx run`; the exec service (`/v1/exec`, `mcpx_exec`) | the exec service only when the caller sent its working directory | the directory the caller ran mcpx from, which a remote run cannot discover | the generated client (paths.cwd, and cwd scoping) | -| `MCPX_PID` | `mcpx exec` / `mcpx run`; the exec service (`/v1/exec`, `mcpx_exec`) | always | the pid of the mcpx process that started the script | the generated client, for pid scoping | -| `MCPX_ENTRY` | the runner, for every script | always | the file the runtime was started on: mcpx's generated launcher, or the script itself under --no-launcher. For exec the script is a generated file | the generated client (paths.entry) | -| `MCPX_CLIENT` | the runner, for every script | always | the generated client module | the generated client (paths.client) | -| `MCPX_CONFIG_PATH` | `mcpx exec` / `mcpx run` | always | the nearest configuration file in effect, empty when there is none | the generated client (paths.config) | -| `MCPX_PATHS_CONFIG` | `mcpx exec` / `mcpx run` | a daemon auto-started by this invocation, only when a --paths-config seed lives in this process's memory; an environment seed needs no forwarding, as the child inherits the environment | the paths.config seed this process resolved configuration discovery from, forwarded so the auto-started daemon resolves the same chain this process did | `mcpx` run inside the script or shell, in configuration discovery (a bootstrap read: paths.config decides which files the settings are read from, so there is no resolved Set to ask); also the setting `paths.config` | -| `MCPX_SCRIPT_DIRS` | `mcpx exec` / `mcpx run` | always | the directories searched for named scripts, nearest first, colon-separated | the generated client (paths.scriptDirs) | -| `MCPX_API_DECLARATION_SHA256` | `mcpx exec` / `mcpx run` | always | the fingerprint of a declared API's declaration, set on the child a declared API launches: PoolID hashes the environment, so editing the declaration replaces the pool instead of keeping a child started for the old one | the pool, as a pool identity input (api serve: PoolID hashes the server environment) | -| `MCPX_ADAPTER_DECLARATION_SHA256` | `mcpx exec` / `mcpx run` | always | the fingerprint of an adapter's declaration, set on the server an adapter launches: PoolID hashes the environment, so editing the declaration replaces the pool instead of keeping a child started for the old one | the pool, as a pool identity input (PoolID hashes the server environment); the daemon, which exempts an adapter's own exact name from the namespace-collision check when the adapter is replaced | -| `MCPX_RUNTIME` | the runner, for every script | always | deno, bun or node; on a dispatched run, the interpreter's name (sh, python3) | the generated client; on a dispatched run, the script itself | -| `MCPX_DISPATCH` | the runner, for every script | only on a dispatched (non-JavaScript) run | how the interpreter was chosen: shebang or interpreter (script.interpreter) | the script itself, and anyone reading its environment | -| `MCPX_ALLOW_READ` | the runner, for every script | only when the permissions allow reading files | 1: the client's file helpers may read. Without it they refuse, naming the permission, rather than leaving it to the sandbox | the generated client | -| `MCPX_LOG_LEVEL` | `mcpx exec` / `mcpx run` | always | the lowest level the script's log keeps | the generated client; `mcpx` run inside the script or shell reads it as logging.level; also the setting `logging.level` | -| `MCPX_LOG_SOURCE` | `mcpx exec` / `mcpx run` | always | which levels record a call site: a level name for that level and above, 0 for none | the generated client | -| `MCPX_DAEMON_ENDPOINT` | the opencode plugin | plugin.env=standard or above, once the plugin has chosen a daemon | the daemon this editor session settled on, so a shell command that runs mcpx talks to the same one instead of looking for its own | `mcpx` run inside the script or shell, as daemon.endpoint; the plugin, as the daemon to use; also the setting `daemon.endpoint` | -| `MCPX_TRACE_IDS` | the opencode plugin | plugin.env=standard or above, when there is anything to say | JSON pairs such as [["session_id","abc"],["worktree","/p"]], extended at full with the parent session and the whole ancestry | `mcpx` run inside the script or shell, which puts every pair on every log record | -| `MCPX_CALL_ID` | the opencode plugin | plugin.env=standard or above | the editor's id for this one tool call | the command | -| `MCPX_OPENCODE_CWD` | the opencode plugin | plugin.env=standard or above | the directory the command runs in, which is not always the project root | the command | -| `MCPX_OPENCODE_DIRECTORY` | the opencode plugin | plugin.env=standard or above | the project directory the editor opened | the command | -| `MCPX_OPENCODE_WORKTREE` | the opencode plugin | plugin.env=standard or above | the project's worktree | the command | -| `MCPX_WORKTREE_NAME` | the opencode plugin | plugin.env=standard or above, when there is a worktree | the worktree's last path element | the command | -| `MCPX_PROJECT_ID` | the opencode plugin | plugin.env=standard or above | the editor's project id | the command | -| `MCPX_HARNESS` | the opencode plugin | plugin.env=standard or above | opencode | the command | -| `MCPX_HARNESS_VERSION` | the opencode plugin | plugin.env=standard or above | the editor's version | the command | -| `MCPX_HARNESS_PID` | the opencode plugin | plugin.env=standard or above | the editor's pid | the command | -| `MCPX_HARNESS_STARTED` | the opencode plugin | plugin.env=standard or above | when the plugin started | the command | -| `MCPX_SHELL_SEQ` | the opencode plugin | plugin.env=standard or above | a counter of shell commands in this editor process | the command | -| `MCPX_SESSION_TITLE` | the opencode plugin | plugin.env=full | the session's title | the command | -| `MCPX_SESSION_DIRECTORY` | the opencode plugin | plugin.env=full | the session's directory | the command | -| `MCPX_SESSION_VERSION` | the opencode plugin | plugin.env=full | the editor version that created the session | the command | -| `MCPX_SESSION_DEPTH` | the opencode plugin | plugin.env=full | how many parents the session has | the command | -| `MCPX_SESSION_CREATED` | the opencode plugin | plugin.env=full, when known | when the session was created, ISO 8601 | the command | -| `MCPX_SESSION_AGE_MS` | the opencode plugin | plugin.env=full, when known | the session's age when the command started, in milliseconds | the command | +| variable | set by | when | what it is | read by | +| --- | --- | --- | --- | --- | +| `MCPX_SESSION` | `mcpx exec` / `mcpx run`; the exec service (`/v1/exec`, `mcpx_exec`); an event consumer | always | the session key this run's tool calls are leased under: --session, else MCPX_SESSION_ID, else one minted for the run | the generated client, which sends it with every call | +| `MCPX_SESSION_ID` | `mcpx exec` / `mcpx run`; the exec service (`/v1/exec`, `mcpx_exec`); an event consumer; the opencode plugin; the plugin loader, for a discovered plugin | the CLI passes through the value it was given, which may be empty; the plugin sets it at every plugin.env level | the session the host assigned. Unlike MCPX_SESSION it survives from one command to the next, so it is what session-scoped servers key on | `mcpx` run inside the script or shell, as its session when --session is not given | +| `MCPX_PARENT_SESSION_ID` | `mcpx exec` / `mcpx run`; an event consumer; the opencode plugin | the CLI passes through what it was given; the daemon passes the caller's parent session into a script run's environment; the plugin at plugin.env=full, when there is a parent | the session that spawned this one, so a parent agent and its subagents can share a server | `mcpx` run inside the script or shell, and the generated client for parent-session scoping | +| `MCPX_EPHEMERAL` | `mcpx exec` / `mcpx run`; the exec service (`/v1/exec`, `mcpx_exec`) | always | 1 when the session key was minted for this run alone, so its instances may be stopped as soon as it ends | the generated client | +| `MCPX_RUN` | `mcpx exec` / `mcpx run`; the exec service (`/v1/exec`, `mcpx_exec`) | always | this execution's run id, which groups the artifacts it produces | the generated client, when storing an artifact | +| `MCPX_INPUT` | `mcpx exec` / `mcpx run` | mcpx exec and mcpx run, locally and with --remote; not when mcpx serve collects the output | report: nothing in this run can answer a server's question mid-call, so a call that asks one exits 75 with the question instead of waiting for it to expire | the generated client, sent as X-Mcpx-Input | +| `MCPX_HOOK_NAME` | the declared-hook runner, for a hook it runs | always | the declared name of the hook being run | the hook itself | +| `MCPX_HOOK_PHASE` | the declared-hook runner, for a hook it runs; the exec service (`/v1/exec`, `mcpx_exec`) | always | the hook's phase; always observe for config-declared hooks, the exec hook's phase (pre, post, onError, onSuccess) for a per-call exec hook | the hook itself | +| `MCPX_HOOK_POINT` | the exec service (`/v1/exec`, `mcpx_exec`) | always | the point the hook is attached to; script for per-call exec hooks in this version | the hook itself | +| `MCPX_HOOK_ERROR` | the exec service (`/v1/exec`, `mcpx_exec`) | only for a hook running because the script failed; truncated to 1024 bytes | the error the hook is running for, in one line; the full hook context is JSON on stdin | the hook itself | +| `MCPX_HOOK_EVENT_KIND` | the declared-hook runner, for a hook it runs | always | the kind of the event the hook is running for; the full event is JSON on stdin | the hook itself | +| `MCPX_HOOK_EVENT_SEQ` | the declared-hook runner, for a hook it runs | always | the event's sequence number on the daemon's bus | the hook itself | +| `MCPX_HOOK_EVENT_SERVER` | the declared-hook runner, for a hook it runs | empty when the event names no server | the server the event is about | the hook itself | +| `MCPX_HOOK_EVENT_SESSION` | the declared-hook runner, for a hook it runs | empty when the event belongs to no session | the session the event belongs to | the hook itself | +| `MCPX_HOOK_EVENT_URI` | the declared-hook runner, for a hook it runs | empty when the event names no resource | the resource URI the event is about | the hook itself | +| `MCPX_ENDPOINT` | `mcpx exec` / `mcpx run`; the exec service (`/v1/exec`, `mcpx_exec`); an event consumer | always | the daemon's HTTP endpoint | the generated client; the plugin as a fallback for MCPX_DAEMON_ENDPOINT | +| `MCPX_SOCKET` | `mcpx exec` / `mcpx run`; the exec service (`/v1/exec`, `mcpx_exec`); the plugin loader, for a discovered plugin | empty when the daemon is remote, since its socket is not reachable from here | the daemon's unix socket, which is faster than the endpoint. Also where a daemon binds and a client dials, for anyone who sets it by hand | the generated client, `mcpx` run inside the script or shell, the plugin | +| `MCPX_TRANSPORT_BEARER_TOKEN` | `mcpx exec` / `mcpx run`; the exec service (`/v1/exec`, `mcpx_exec`); an event consumer | only when transport.bearerToken is configured | the daemon's bearer token, handed to the script so the generated client can authenticate to a daemon that requires it (#1975); the token itself stays out of the generated code | the generated client, `mcpx` run inside the script or shell, the plugin; also the setting `transport.bearerToken` | +| `MCPX_SETTINGS` | `mcpx exec` / `mcpx run`; the exec service (`/v1/exec`, `mcpx_exec`) | only when the caller sent call settings with the run (for example a requested pool.callTimeout) | the call-settings header for this run, carried into the script so the generated client forwards the caller's per-call requests on the calls it makes on the script's behalf | the generated client, which sends it as the x-mcpx-settings header | +| `MCPX_ARTIFACTS_LOCAL` | `mcpx exec` / `mcpx run`; the exec service (`/v1/exec`, `mcpx_exec`) | always | 1 when the daemon shares this filesystem, so artifact({path}) may hand over a path instead of the bytes | the generated client | +| `MCPX_CWD` | `mcpx exec` / `mcpx run`; the exec service (`/v1/exec`, `mcpx_exec`) | the exec service only when the caller sent its working directory | the directory the caller ran mcpx from, which a remote run cannot discover | the generated client (paths.cwd, and cwd scoping) | +| `MCPX_PID` | `mcpx exec` / `mcpx run`; the exec service (`/v1/exec`, `mcpx_exec`) | always | the pid of the mcpx process that started the script | the generated client, for pid scoping | +| `MCPX_ENTRY` | the runner, for every script | always | the file the runtime was started on: mcpx's generated launcher, or the script itself under --no-launcher. For exec the script is a generated file | the generated client (paths.entry) | +| `MCPX_CLIENT` | the runner, for every script | always | the generated client module | the generated client (paths.client) | +| `MCPX_CONFIG_PATH` | `mcpx exec` / `mcpx run` | always | the nearest configuration file in effect, empty when there is none | the generated client (paths.config) | +| `MCPX_PATHS_CONFIG` | `mcpx exec` / `mcpx run` | a daemon auto-started by this invocation, only when a --paths-config seed lives in this process's memory; an environment seed needs no forwarding, as the child inherits the environment | the paths.config seed this process resolved configuration discovery from, forwarded so the auto-started daemon resolves the same chain this process did | `mcpx` run inside the script or shell, in configuration discovery (a bootstrap read: paths.config decides which files the settings are read from, so there is no resolved Set to ask); also the setting `paths.config` | +| `MCPX_SCRIPT_DIRS` | `mcpx exec` / `mcpx run` | always | the directories searched for named scripts, nearest first, colon-separated | the generated client (paths.scriptDirs) | +| `MCPX_API_DECLARATION_SHA256` | `mcpx exec` / `mcpx run` | always | the fingerprint of a declared API's declaration, set on the child a declared API launches: PoolID hashes the environment, so editing the declaration replaces the pool instead of keeping a child started for the old one | the pool, as a pool identity input (api serve: PoolID hashes the server environment) | +| `MCPX_ADAPTER_DECLARATION_SHA256` | `mcpx exec` / `mcpx run` | always | the fingerprint of an adapter's declaration, set on the server an adapter launches: PoolID hashes the environment, so editing the declaration replaces the pool instead of keeping a child started for the old one | the pool, as a pool identity input (PoolID hashes the server environment); the daemon, which exempts an adapter's own exact name from the namespace-collision check when the adapter is replaced | +| `MCPX_RUNTIME` | the runner, for every script | always | deno, bun or node; on a dispatched run, the interpreter's name (sh, python3) | the generated client; on a dispatched run, the script itself | +| `MCPX_DISPATCH` | the runner, for every script | only on a dispatched (non-JavaScript) run | how the interpreter was chosen: shebang or interpreter (script.interpreter) | the script itself, and anyone reading its environment | +| `MCPX_ALLOW_READ` | the runner, for every script | only when the permissions allow reading files | 1: the client's file helpers may read. Without it they refuse, naming the permission, rather than leaving it to the sandbox | the generated client | +| `MCPX_LOG_LEVEL` | `mcpx exec` / `mcpx run` | always | the lowest level the script's log keeps | the generated client; `mcpx` run inside the script or shell reads it as logging.level; also the setting `logging.level` | +| `MCPX_LOG_SOURCE` | `mcpx exec` / `mcpx run` | always | which levels record a call site: a level name for that level and above, 0 for none | the generated client | +| `MCPX_DAEMON_ENDPOINT` | the opencode plugin | plugin.env=standard or above, once the plugin has chosen a daemon | the daemon this editor session settled on, so a shell command that runs mcpx talks to the same one instead of looking for its own | `mcpx` run inside the script or shell, as daemon.endpoint; the plugin, as the daemon to use; also the setting `daemon.endpoint` | +| `MCPX_TRACE_IDS` | the opencode plugin | plugin.env=standard or above, when there is anything to say | JSON pairs such as [["session_id","abc"],["worktree","/p"]], extended at full with the parent session and the whole ancestry | `mcpx` run inside the script or shell, which puts every pair on every log record | +| `MCPX_CALL_ID` | the opencode plugin | plugin.env=standard or above | the editor's id for this one tool call | the command | +| `MCPX_OPENCODE_CWD` | the opencode plugin | plugin.env=standard or above | the directory the command runs in, which is not always the project root | the command | +| `MCPX_OPENCODE_DIRECTORY` | the opencode plugin | plugin.env=standard or above | the project directory the editor opened | the command | +| `MCPX_OPENCODE_WORKTREE` | the opencode plugin | plugin.env=standard or above | the project's worktree | the command | +| `MCPX_WORKTREE_NAME` | the opencode plugin | plugin.env=standard or above, when there is a worktree | the worktree's last path element | the command | +| `MCPX_PROJECT_ID` | the opencode plugin | plugin.env=standard or above | the editor's project id | the command | +| `MCPX_HARNESS` | the opencode plugin | plugin.env=standard or above | opencode | the command | +| `MCPX_HARNESS_VERSION` | the opencode plugin | plugin.env=standard or above | the editor's version | the command | +| `MCPX_HARNESS_PID` | the opencode plugin | plugin.env=standard or above | the editor's pid | the command | +| `MCPX_HARNESS_STARTED` | the opencode plugin | plugin.env=standard or above | when the plugin started | the command | +| `MCPX_SHELL_SEQ` | the opencode plugin | plugin.env=standard or above | a counter of shell commands in this editor process | the command | +| `MCPX_SESSION_TITLE` | the opencode plugin | plugin.env=full | the session's title | the command | +| `MCPX_SESSION_DIRECTORY` | the opencode plugin | plugin.env=full | the session's directory | the command | +| `MCPX_SESSION_VERSION` | the opencode plugin | plugin.env=full | the editor version that created the session | the command | +| `MCPX_SESSION_DEPTH` | the opencode plugin | plugin.env=full | how many parents the session has | the command | +| `MCPX_SESSION_CREATED` | the opencode plugin | plugin.env=full, when known | when the session was created, ISO 8601 | the command | +| `MCPX_SESSION_AGE_MS` | the opencode plugin | plugin.env=full, when known | the session's age when the command started, in milliseconds | the command | +| `MCPX_SUPERVISOR_OWNER_PID` | the client pool, arming the supervisor owner watch | a test suite arms the watch via EnableSupervisorOwnerWatch (internal/testsupport); production daemons never set it | the PID of the process a supervisor belongs to; when that process dies, the supervisor terminates its child and exits instead of leaking (#10774) | `mcpx` run inside the script or shell, which arms the supervisors it spawns (internal/mcpclient owner watch) | diff --git a/pkgs/mcpx/internal/settings/scriptenv.go b/pkgs/mcpx/internal/settings/scriptenv.go index 17f13b0b22..485d9c9ec3 100644 --- a/pkgs/mcpx/internal/settings/scriptenv.go +++ b/pkgs/mcpx/internal/settings/scriptenv.go @@ -42,6 +42,10 @@ const ( // uses to call /v1. Not SetByPlugin -- that is the opencode plugin, a // consumer of mcpx, where this is mcpx loading a plugin of its own. SetByPluginLoader Setter = "plugin-loader" + // SetByPool is the client pool (internal/mcpclient), which arms the + // supervisor owner watch in its own environment so that every + // supervisor it spawns inherits the owner PID (#10774). + SetByPool Setter = "pool" ) // Describe is the setter as a reader of the documentation knows it. @@ -59,6 +63,8 @@ func (s Setter) Describe() string { return "the opencode plugin" case SetByPluginLoader: return "the plugin loader, for a discovered plugin" + case SetByPool: + return "the client pool, arming the supervisor owner watch" case SetByHooks: return "the declared-hook runner, for a hook it runs" } @@ -378,5 +384,14 @@ func ScriptEnv() []EnvVar { Meaning: "when the session was created, ISO 8601", ReadBy: "the command"}, {Name: "MCPX_SESSION_AGE_MS", SetBy: []Setter{SetByPlugin}, When: "plugin.env=full, when known", Meaning: "the session's age when the command started, in milliseconds", ReadBy: "the command"}, + // ---- the supervisor owner watch ---- + { + Name: "MCPX_SUPERVISOR_OWNER_PID", + SetBy: []Setter{SetByPool}, + When: "a test suite arms the watch via EnableSupervisorOwnerWatch (internal/testsupport); production daemons never set it", + Meaning: "the PID of the process a supervisor belongs to; when that process dies, " + + "the supervisor terminates its child and exits instead of leaking (#10774)", + ReadBy: nested + ", which arms the supervisors it spawns (internal/mcpclient owner watch)", + }, } } diff --git a/pkgs/mcpx/internal/settings/scriptenv_test.go b/pkgs/mcpx/internal/settings/scriptenv_test.go index 74da2e44b0..f381936b92 100644 --- a/pkgs/mcpx/internal/settings/scriptenv_test.go +++ b/pkgs/mcpx/internal/settings/scriptenv_test.go @@ -22,6 +22,7 @@ var setterSources = map[settings.Setter]string{ settings.SetByPlugin: "plugin/opencode/", settings.SetByPluginLoader: "internal/plugin/", settings.SetByHooks: "internal/hooks/", + settings.SetByPool: "internal/mcpclient/", } func setterOf(file string) (settings.Setter, bool) {