/**
 * Minified by jsDelivr using Terser v5.39.0.
 * Original file: /npm/@mariozechner/terminalcp@1.3.3/dist/index.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
#!/usr/bin/env node
import*as fs from"node:fs";import*as os from"node:os";import*as path from"node:path";import{fileURLToPath}from"node:url";import{AttachClient}from"./attach-client.js";import{parseKeyInput}from"./key-parser.js";import{runMCPServer}from"./mcp-server.js";import{TerminalClient}from"./terminal-client.js";import{TerminalServer}from"./terminal-server.js";const __dirname=path.dirname(fileURLToPath(import.meta.url)),packageJsonPath=path.join(__dirname,"..","package.json"),packageJson=JSON.parse(fs.readFileSync(packageJsonPath,"utf-8")),CLIENT_VERSION=packageJson.version,args=process.argv.slice(2);if(0===args.length&&(console.log('terminalcp - Terminal Control Protocol\nA centralized terminal session manager with MCP server support\n\nUSAGE:\n  terminalcp --mcp                       Start as MCP server for Claude Desktop\n  terminalcp --server                    Start the terminal server daemon\n  terminalcp <command> [options]         Run a CLI command\n\nCOMMANDS:\n  list, ls                               List all active sessions\n  start <id> <command>                   Start a new named session\n  stop [id]                              Stop session(s) (all if no id given)\n  attach <id>                            Attach to a session interactively\n  stdout <id> [lines]                    Get terminal output (rendered view)\n  stream <id> [opts]                     Get raw output stream\n  stdin <id> <data>                      Send input to a session\n  resize <id> <cols> <rows>              Resize terminal dimensions\n  term-size <id>                         Get terminal size\n  version                                Show client and server versions\n  kill-server                            Shutdown the terminal server\n\nEXAMPLES:\n  # Start as MCP server for Claude Desktop\n  terminalcp --mcp\n\n  # Start a development server\n  terminalcp start dev-server "npm run dev"\n\n  # Start an interactive Python session\n  terminalcp start python "python3 -i"\n  terminalcp stdin python "print(\'Hello\')\r"\n  terminalcp stdout python\n\n  # Debug with lldb\n  terminalcp start debug "lldb ./myapp"\n  terminalcp stdin debug "b main\r"\n  terminalcp stdin debug "run\r"\n  terminalcp attach debug  # Interactive debugging\n\n  # Monitor build output\n  terminalcp start build "npm run build"\n  terminalcp stream build --since-last\n\n  # Attach to interact with a session\n  terminalcp attach python\n  # Press Ctrl+B to detach\n\nOPTIONS:\n  --mcp                                  Run as MCP server on stdio\n  --server                               Run as terminal server daemon\n  --since-last                           Only show new output (stream)\n  --with-ansi                            Keep ANSI codes (stream)\n\nCLAUDE DESKTOP CONFIGURATION:\n  Add to claude_desktop_config.json:\n  {\n    "mcpServers": {\n      "terminalcp": {\n        "command": "npx",\n        "args": ["-y", "@mariozechner/terminalcp", "--mcp"]\n      }\n    }\n  }\n\nFor more information: https://github.com/badlogic/terminalcp'),process.exit(0)),"--mcp"===args[0])runMCPServer().catch((e=>{console.error("Fatal error:",e),process.exit(1)}));else if(args.length>0)if("ls"===args[0]||"list"===args[0]){(new TerminalClient).request({action:"list"}).then((e=>{const s=e.split("\n").filter((e=>e.trim()));if(0===s.length)console.log("No active sessions");else for(const e of s){const[s,r,t,...n]=e.split(" "),o=n.join(" ");console.log(`  ${s}`),console.log(`    Status: ${r}`),console.log(`    CWD: ${t}`),console.log(`    Command: ${o}`),console.log()}process.exit(0)})).catch((e=>{"No server running"===e.message&&(console.log("No active sessions"),process.exit(0)),console.error(e.message),process.exit(1)}))}else if("start"===args[0]){args.length<3&&(console.error("Usage: terminalcp start <session-id> <command> [args...]"),process.exit(1));const e=args[1],s=args.slice(2).join(" ");(new TerminalClient).request({action:"start",command:s,name:e}).then((e=>{console.log(`Started session: ${e}`),process.exit(0)})).catch((e=>{console.error("Failed to start session:",e.message),process.exit(1)}))}else if("stop"===args[0]){const e=args[1];(new TerminalClient).request({action:"stop",id:e}).then((e=>{console.log(e),process.exit(0)})).catch((e=>{console.error("Failed to stop session:",e.message),process.exit(1)}))}else if("stdout"===args[0]){args[1]||(console.error("Usage: terminalcp stdout <id> [lines]"),process.exit(1));const e=new TerminalClient,s=args[2]?parseInt(args[2]):void 0;e.request({action:"stdout",id:args[1],lines:s}).then((e=>{process.stdout.write(e),process.exit(0)})).catch((e=>{console.error("Failed to get stdout:",e.message),process.exit(1)}))}else if("stream"===args[0]){args[1]||(console.error("Usage: terminalcp stream <id> [--since-last] [--with-ansi]"),process.exit(1));const e=new TerminalClient,s=args.includes("--since-last"),r=!args.includes("--with-ansi");e.request({action:"stream",id:args[1],since_last:s,strip_ansi:r}).then((e=>{process.stdout.write(e),process.exit(0)})).catch((e=>{console.error("Failed to get stream:",e.message),process.exit(1)}))}else if("stdin"===args[0]){args.length<3&&(console.error("Usage: terminalcp stdin <id> <text> [text] ..."),console.error("\nUse :: prefix for special keys:"),console.error('  terminalcp stdin session "hello world" ::Enter'),console.error("  terminalcp stdin session hello ::Space world ::Enter"),console.error('  terminalcp stdin session "echo test" ::Left ::Left ::Left "hi " ::Enter'),console.error('  terminalcp stdin session ::C-c "echo done" ::Enter'),console.error("\nSpecial keys: ::Up, ::Down, ::Left, ::Right, ::Enter, ::Tab, ::Space"),console.error("              ::Home, ::End, ::PageUp, ::PageDown, ::Insert, ::Delete"),console.error("              ::F1-F12, ::BSpace, ::C-<key>, ::M-<key>, ::^<key>"),process.exit(1));const e=new TerminalClient,s=parseKeyInput(args.slice(2));e.request({action:"stdin",id:args[1],data:s}).then((()=>{process.exit(0)})).catch((e=>{console.error("Failed to send stdin:",e.message),process.exit(1)}))}else if("term-size"===args[0]){args[1]||(console.error("Usage: terminalcp term-size <id>"),process.exit(1));(new TerminalClient).request({action:"term-size",id:args[1]}).then((e=>{console.log(e),process.exit(0)})).catch((e=>{console.error("Failed to get terminal size:",e.message),process.exit(1)}))}else if("resize"===args[0]){args.length<4&&(console.error("Usage: terminalcp resize <id> <cols> <rows>"),process.exit(1));(new TerminalClient).request({action:"resize",id:args[1],cols:parseInt(args[2]),rows:parseInt(args[3])}).then((()=>{console.log("Terminal resized"),process.exit(0)})).catch((e=>{console.error("Failed to resize terminal:",e.message),process.exit(1)}))}else if("attach"===args[0]){args[1]||(console.error("Usage: terminalcp attach <id>"),process.exit(1));(new AttachClient).attach(args[1]).catch((e=>{console.error(e.message),process.exit(1)}))}else if("version"===args[0]){(new TerminalClient).request({action:"version"}).then((e=>{console.log(`Server version: ${e}`),console.log(`Client version: ${CLIENT_VERSION}`),process.exit(0)})).catch((e=>{console.error("Failed to get server version:",e.message),console.log(`Client version: ${CLIENT_VERSION}`),process.exit(1)}))}else if("kill-server"===args[0]){const e=path.join(os.homedir(),".terminalcp","server.sock");fs.existsSync(e)||(console.error("No server running"),process.exit(1));(new TerminalClient).request({action:"kill-server"}).then((()=>{console.log("Server killed"),process.exit(0)})).catch((e=>{console.error("Failed to kill server:",e.message),process.exit(1)}))}else if("--server"===args[0]){(new TerminalServer).start().catch((e=>{console.error("Failed to start server:",e),process.exit(1)}))}else console.error(`Unknown command: ${args[0]}`),console.error("Run 'terminalcp' without arguments to see help"),process.exit(1);
//# sourceMappingURL=/sm/270b663510013d18b4e032f281b5f31c2e34a57a7e30d64c53f24605563e7ffb.map