Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Heuristic:2giosangmitom Sqmeow nvim Engine Stdout RPC Only

From Leeroopedia
Knowledge Sources
Domains Debugging, Infrastructure, RPC
Last Updated 2026-10-16 14:00 GMT

Overview

Tribal knowledge that the sqmeow-core engine's stdout is exclusively reserved for MessagePack-RPC frames — any other output to stdout corrupts the protocol. All diagnostics and tracing go to stderr.

Description

The engine communicates with Neovim through a MessagePack-RPC transport over stdio. The Connection::stdio() transport reads RPC frames from stdin and writes replies/events to stdout. Any byte written to stdout that is not a valid MessagePack frame desynchronizes the protocol and breaks the editor-engine channel.

Tracing output (log messages, debug info) is directed to stderr via tracing_subscriber::fmt().with_writer(std::io::stderr). ANSI color codes are disabled because the editor displays stderr as plain text. The log level is controlled by the SQMEOW_LOG environment variable (default: warn).

This is a hard architectural constraint: stdout belongs to the protocol. Any code running in the engine process — including adapter code, SSH tunnel code, or future features — must never write to stdout.

Usage

Use this heuristic when:

  • Debugging the engine: Set SQMEOW_LOG=debug (or trace) to see diagnostics on stderr. Never add println! to engine code — use tracing::debug! or tracing::warn!.
  • Diagnosing protocol corruption: If the editor shows garbled messages or the connection drops, check for any stdout output from the engine or spawned child processes.
  • Adding new code: Ensure all diagnostics use tracing macros, not println! or eprintln!. The eprintln! macro is only used in main() before tracing is initialized.
  • Spawning child processes: The SSH tunnel code redirects child stdout to Stdio::null() to prevent SSH's output from corrupting the RPC channel.

The Insight (Rule of Thumb)

  • Action: Never write to stdout in the engine process. Use tracing macros for all diagnostics. Redirect child process stdout to Stdio::null().
  • Value: SQMEOW_LOG controls the filter level (default warn). ANSI disabled. Tracing goes to stderr via with_writer(std::io::stderr).
  • Trade-off: Using stderr for diagnostics means the editor can show them as plain text messages, but they are interleaved with protocol-adjacent output. The with_ansi(false) setting ensures readability.
  • Compatibility: Applies to the entire sqmeow-core binary. Adapter crates that log via tracing are safe; any direct stdout output would break the protocol.

Reasoning

The MessagePack-RPC transport is a binary protocol. The reader on the editor side expects every byte on stdout to be part of a valid MessagePack frame. A single println!("hello") would inject 6 bytes of ASCII text before the next frame, causing the deserializer to fail or misparse, and the editor would lose track of message boundaries.

This is why the engine initializes tracing with .with_writer(std::io::stderr) explicitly — the default for tracing_subscriber::fmt() is stderr, but the code makes it explicit with a comment: "stdout belongs to the protocol."

The SSH tunnel code takes the same precaution: the spawned ssh process has stdout(Stdio::null()) so SSH's own output (e.g. connection banners) cannot leak into the engine's stdout. Only stderr is piped for error reporting.

Code Evidence

Tracing initialization with stderr writer from core/sqmeow-core/src/main.rs:63-73:

fn init_tracing() {
    let filter = EnvFilter::try_from_env("SQMEOW_LOG").unwrap_or_else(|_| EnvFilter::new("warn"));
    tracing_subscriber::fmt()
        // stdout belongs to the protocol.
        .with_writer(std::io::stderr)
        // The editor shows stderr as plain text.
        .with_ansi(false)
        .with_env_filter(filter)
        .with_target(false)
        .init();
}

stdio transport from core/sqmeow-core/src/main.rs:49:

let connection = Connection::stdio();

SSH child process stdout redirected to null from core/sqmeow-core/src/server/tunnel.rs:79-83:

let mut child = command
    .arg(destination)
    .stdin(Stdio::null())
    .stdout(Stdio::null())
    .stderr(Stdio::piped())
    .kill_on_drop(true)
    .spawn()

AGENTS.md constraint from AGENTS.md:24:

- Reserve engine stdout for RPC frames; send diagnostics to stderr via tracing (`SQMEOW_LOG`).

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment