#!/bin/zsh -f
emulate -LR zsh
setopt ERR_EXIT NO_UNSET PIPE_FAIL
[[ $# == 6 && "$1" == --host && "$2" == 127.0.0.1 && "$3" == --port && "$4" == <1-65535> && "$5" == --token ]] || exit 1
sc_port=$4 sc_token=$6
[[ ${#sc_token} == 32 && "$sc_token" != *[^a-zA-Z0-9_-]* ]] || exit 1
# The handshake is sent once; thereafter bytes are relayed unchanged in both directions.
# macOS nc half-closes on stdin EOF and finishes when the main-owned bridge closes its socket.
{ print -r -- "{\"token\":\"$sc_token\",\"type\":\"supercode-claude-mcp-connect\"}"; /bin/cat; } | /usr/bin/nc -n -G 5 127.0.0.1 "$sc_port"
