const MUXCLIENT_JS: &str = "// Copyright 2026, AgentMux Corp.\n// SPDX-License-Identifier: Apache-2.0\n//\n// Shared plumbing for every muxsh-family Node CLI (muxspect, muxopen, muxsh,\n// and future additions \u{2014} see\n// docs/specs/SPEC_MUXSH_FULL_COLLECTION_2026_09_16.md \u{a7}2.8): reading the\n// $AGENTMUX_LOCAL_URL/$AGENTMUX_AUTH_KEY pair every authenticated core needs,\n// and building the authenticated fetch() call every core makes against\n// agentmux-srv\'s REST API.\n//\n// Deliberately does NOT read the response body. Each existing tool\'s\n// error-handling strategy differs in ways worth preserving exactly (some\n// read .json() on success and .text() on failure; some read .json() always\n// with a {} fallback on parse failure) \u{2014} unifying that part would risk\n// silently changing what each tool prints on a real failure. This module\n// only shares the part that was genuinely byte-identical everywhere: env\n// lookup and the fetch() call itself.\n\n/** Read the auth pair from the environment. Pure \u{2014} no validation, no I/O, no\n * process.exit. Callers decide what \"missing\" means for their own error\n * message and exit code (wording has legitimately differed per tool; this\n * doesn\'t force it to converge). */\nexport function readAgentmuxEnv(env = process.env) {\n return { url: env.AGENTMUX_LOCAL_URL, authKey: env.AGENTMUX_AUTH_KEY };\n}\n\n/** Perform an authenticated request against agentmux-srv\'s REST API.\n *\n * Returns `{ resp, ok, status }` \u{2014} the raw `Response` plus convenience\n * fields \u{2014} without reading the body, so callers remain free to call\n * `.json()` or `.text()` exactly as they already do. Throws on network\n * failure (DNS, connection refused, etc.); every existing caller already\n * wraps this in its own try/catch with its own fail() wording.\n */\nexport async function agentmuxFetch(url, authKey, path, { method = \"GET\", body } = {}) {\n const headers = { \"X-AuthKey\": authKey };\n const init = { method, headers };\n if (body !== undefined) {\n headers[\"Content-Type\"] = \"application/json\";\n init.body = JSON.stringify(body);\n }\n const resp = await fetch(`${url.replace(/\\/$/, \"\")}${path}`, init);\n return { resp, ok: resp.ok, status: resp.status };\n}\n";Expand description
Shared auth-env-read + authenticated-fetch plumbing every core above
(except muxlog, which does no REST calls) imports via a relative
./lib/muxclient.mjs — so it must be deployed at <shell>/lib/, not
flat beside its callers. See
docs/specs/SPEC_MUXSH_FULL_COLLECTION_2026_09_16.md §2.8.