Skip to content

Fix bare-host connections and input handling; add history and Ctrl+R - #170

Open
WietseWind wants to merge 6 commits into
websockets:masterfrom
WietseWind:feature/persistent-history
Open

Fix bare-host connections and input handling; add history and Ctrl+R#170
WietseWind wants to merge 6 commits into
websockets:masterfrom
WietseWind:feature/persistent-history

Conversation

@WietseWind

@WietseWind WietseWind commented Sep 9, 2026

Copy link
Copy Markdown

Fixes

  • Assume ws:// when the connection address has no protocol.
    wscat -c localhost:4000 now works. Keep explicit protocols, paths, and queries.

  • Fix paste at the cursor on Node.js 24, including macOS. Keep the text before
    and after the cursor. Preserve Unicode and handle split UTF-8 input.
    Bracketed paste also works during history search.

  • Make Ctrl+C clear input or history search text first. Keep the connection
    open and return to an empty prompt. Ctrl+C at an empty prompt closes the
    session. Cancelled text is neither sent nor saved.

Additions

  • Save commands to ~/.wscat_history for global npm and Bun installations.
    Load the last 1,000 entries. Append each command when submitted so sessions
    can share the file.
  • Add --history for local runs and --no-history to turn file storage off.
    If detection or file access fails, continue silently with history in memory.
  • Add Ctrl+R to search history. Press it again for an older match. Enter sends
    the command. Escape selects it for editing. Ctrl+G cancels the search.
    Search also works with history in memory.
  • Add short usage instructions and 69 tests. No new dependencies.

Demo

Command history and Ctrl+R search in wscat

Full recording: 49 seconds, 2 MB GIF (compressed from 32 MB).

Security overview

No npm packages were added or removed. No unused dependency was introduced.
The existing packages and versions are unchanged: commander parses options,
https-proxy-agent handles proxies, read prompts for passphrases, and ws
handles WebSocket connections.

The changes use built-in Node.js modules:

Modules Change Use
os, path New runtime imports Find the home directory and check installation paths.
stream New runtime import Pass terminal input to readline through PassThrough.
fs Already used Read and append history; check launcher paths.
readline Already used Handle keys, edit commands, and search history.

These modules ship with Node.js. They need no extra npm downloads or install
scripts. Installation detection does not run npm or Bun. Reading or searching
history does not execute its text. The tests use Node's test runner and
assertions. Only tests use child_process to start local CLI processes.

  • History stores submitted messages in plain text. New files use mode 0600
    where Unix permissions apply. Existing permissions stay unchanged. Normal
    filesystem rules apply, including following symbolic links.
  • Use --no-history for sensitive data. Local runs need --history to use the
    file. Piped input/output and --execute do not use it. File errors do not stop
    the session.
  • The file has no size limit. Only the last 1,000 entries become available in
    history, but startup reads the full file. Users can trim or delete it.
  • The URL default is ws://, which is not encrypted. Use wss:// for TLS.
    The change does not alter TLS checks or send data to new services.

Validation

  • All 69 tests pass on Node.js 18.20.8 and 24.11.1. Tests cover URL handling,
    paste, Unicode, saved history, Ctrl+R search, and Ctrl+C cancellation.

  • Installed the packed package globally. Checked bare host connections,
    paste into JSON, Unicode, and pasted search text in a macOS terminal.
    Tests used a local WebSocket server and temporary home directories.

  • Checked Ctrl+C in the global install with a real macOS terminal. Drafts,
    recalled commands, and searches clear without closing the connection.
    A second Ctrl+C closes the empty prompt. Cancelled text is not saved.

@WietseWind WietseWind changed the title [feature] Add persistent command history and reverse search Fix bare-host connections and pasting; add history and Ctrl+R Sep 9, 2026
@WietseWind WietseWind changed the title Fix bare-host connections and pasting; add history and Ctrl+R Fix bare-host connections and input handling; add history and Ctrl+R Sep 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant