#!/usr/bin/env node
/**
 * MCP spawn-tee — parent-side stderr capture wrapper.
 *
 * Claude Code's `--mcp-config` accepts `{command, args, env}` descriptors and
 * spawns each MCP server itself; the platform never holds a ChildProcess
 * handle. The in-process `mcp-stderr-tee` patches `process.stderr.write` from
 * inside the MCP server, but its writes go through `createWriteStream` —
 * async, buffered. A synchronous module-load throw (e.g. schema-loader's
 * line-168 width check on memory) calls `process.exit(1)` before the buffer
 * flushes, so the per-server log file is empty and the platform's
 * `[mcp-init-error] tail="(no stderr file)"` probe is operationally useless.
 * That class shipped as the chronic memory-MCP silent-fail loop fixed by
 * (and hit graph — solved there with per-plugin
 * `appendFileSync` discipline that this wrapper now generalises).
 *
 * The wrapper sits between Claude Code and the real MCP server: it spawns
 * the real entry with `stdio: ['inherit', 'inherit', 'pipe']`, then
 * synchronously appends every child stderr chunk to
 * `${LOG_DIR}/mcp-${name}-stderr-<date>.log`. Synchronous writes survive
 * `process.exit` because the kernel queues the syscall before the call
 * returns. The chunk is also written to the wrapper's own stderr so
 * Claude Code's existing stderr consumer is unchanged — the mechanism is
 * additive, not interceptive.
 *
 *   Claude Code CLI
 *        │ spawns
 *        ▼
 *   wrapper (this file) — argv[2] = real entry, env.MCP_SPAWN_TEE_NAME = name
 *        │ spawns child with stdio:['inherit','inherit','pipe']
 *        ▼
 *   child = node <real-entry>
 *        │
 *        ├──▶ stdin/stdout: inherited from wrapper (Claude Code pipe)
 *        └──▶ stderr → wrapper.on('data', chunk =>)
 *               ├──▶ appendFileSync(${LOG_DIR}/mcp-${name}-stderr-<date>.log)
 *               └──▶ process.stderr.write(chunk)  → Claude Code consumer
 *
 * The wrapper catches:
 *   - MODULE_NOT_FOUND on the entry script itself (success criterion #3:
 *     `mv plugins/memory/mcp/dist plugins/memory/mcp/dist-broken && reboot`
 *     leaves the cause on disk).
 *   - Synchronous throws during module load before the in-process tee runs.
 *   - Any stderr a normally-running plugin emits (steady-state telemetry
 *     remains visible too — the in-process tee handles per-line stream-log
 *     prefixing; this wrapper handles the raw per-server file).
 *
 * SIGTERM/SIGINT propagation: forwarded to the child so a Claude Code
 * shutdown does not orphan the MCP server. Child exit code is propagated
 * verbatim so upstream (Claude Code) sees the real outcome.
 */
export {};
//# sourceMappingURL=index.d.ts.map