@iosifnicolae22/remote-shell
Version:
Run any terminal application and control it remotely from your mobile device. Perfect for maxing out vibe coding sessions with Claude Code on the go!
2 lines (1 loc) • 1.24 kB
JavaScript
;Object.defineProperty(exports,"__esModule",{value:!0}),exports.SlashCommandHandler=void 0;class SlashCommandHandler{commandBuffer="";intercept(e,t,n){const o=e.write.bind(e);e.write=e=>{if(this.commandBuffer+=e,e.includes("\n")){const a=this.commandBuffer.trim();if(this.handleSlashCommand(a,t,n))return void(this.commandBuffer="");this.commandBuffer="",o(e)}}}handleSlashCommand(e,t,n){if(!e.startsWith("/"))return!1;const o=e.substring(1).split(" "),a=o[0].toLowerCase();switch(o.slice(1),a){case"mobile":return this.handleMobileCommand(t,n),!0;case"devices":return this.handleDevicesCommand(n),!0;default:return!1}}handleMobileCommand(e,t){const n=e.generateToken();"createSession"in t?t.createSession(n.token):t.notifySessionCreated(n.token),e.displayConnectionInfo(n.token)}handleDevicesCommand(e){let t=[];"getConnectedDevices"in e&&(t=e.getConnectedDevices()),0===t.length||t.forEach(e=>{this.formatTimestamp(e.connected),this.formatTimestamp(e.lastActivity),e.userAgent})}formatTimestamp(e){const t=(new Date).getTime()-e.getTime(),n=Math.floor(t/1e3),o=Math.floor(n/60),a=Math.floor(o/60);return n<60?`${n}s ago`:o<60?`${o}m ago`:a<24?`${a}h ago`:e.toLocaleString()}}exports.SlashCommandHandler=SlashCommandHandler;