CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-rome

Rome is a toolchain for the web: formatter, linter and more for JavaScript, TypeScript, JSON, HTML, Markdown, and CSS

Pending
Overview
Eval results
Files

daemon-mode.mddocs/

Daemon Mode

Rome's daemon mode provides a persistent server process that significantly improves performance for repeated operations by avoiding startup costs and maintaining parsed state between commands.

Capabilities

Daemon Management

Control Rome's background server process for improved performance.

/**
 * Start the Rome daemon server process
 * 
 * Usage: rome start
 * 
 * Starts a background server process that other Rome commands can connect to
 */
rome start

/**
 * Stop the Rome daemon server process
 * 
 * Usage: rome stop
 * 
 * Stops the running background server process
 */
rome stop

/**
 * Language Server Protocol over stdin/stdout
 * 
 * Usage: rome lsp-proxy
 * 
 * Acts as a server for the Language Server Protocol, typically used by editors
 */
rome lsp-proxy

Using Daemon Mode

Connect to the running daemon for faster command execution.

/**
 * Connect to running daemon instance
 * 
 * Add --use-server to any Rome command to use the daemon
 */
rome check src/ --use-server
rome format src/ --use-server  
rome ci src/ --use-server

Performance Benefits

Startup Time Reduction

The daemon eliminates the overhead of starting the Rust process for each command:

# Without daemon (cold start each time)
rome check src/        # ~200ms startup
rome format src/       # ~200ms startup  
rome ci src/           # ~200ms startup

# With daemon (amortized startup cost)
rome start            # ~200ms startup once
rome check src/ --use-server    # ~20ms
rome format src/ --use-server   # ~20ms
rome ci src/ --use-server       # ~20ms

State Persistence

The daemon maintains parsed state between operations:

  • File system cache: Avoids re-reading unchanged files
  • Parse cache: Reuses parsed ASTs for unchanged files
  • Configuration cache: Avoids re-parsing rome.json
  • Rule cache: Maintains compiled rule state

Usage Examples

Basic Daemon Usage

# Start daemon
rome start

# Use daemon for commands (faster execution)
rome check src/ --use-server
rome format src/ --write --use-server
rome ci src/ --use-server

# Stop daemon when done
rome stop

Development Workflow

# Start daemon at beginning of work session
rome start

# Fast feedback during development
rome check src/components/Button.tsx --use-server
rome format src/components/Button.tsx --write --use-server

# Stop daemon at end of session
rome stop

CI/CD Integration

# Start daemon for build pipeline
rome start

# Run multiple checks efficiently
rome check src/ --use-server
rome format src/ --use-server  
rome ci tests/ --use-server

# Daemon automatically stops when process ends

Daemon Status

Check Daemon Status

# Commands will indicate if daemon is not running
rome check src/ --use-server
# Error: ServerNotRunning - start daemon with 'rome start'

# Check if daemon is running (implicit)
rome start  # Will report if already running

Socket Information

/**
 * Print socket information (internal command)
 * 
 * Usage: rome __print_socket
 * 
 * Internal command that prints daemon socket information for debugging
 */
rome __print_socket

Editor Integration

Language Server Protocol

Rome provides LSP support through the daemon:

rome lsp-proxy

This enables:

  • Real-time diagnostics: Live linting and error reporting
  • Format on save: Automatic formatting in editors
  • Code actions: Quick fixes and refactoring suggestions
  • Hover information: Type and documentation information

Editor Configuration

VS Code

{
  "rome.lspBin": "rome",
  "rome.requireConfiguration": true,
  "editor.formatOnSave": true,
  "editor.codeActionsOnSave": {
    "quickfix.rome": true
  }
}

Neovim

require('lspconfig').rome.setup({
  cmd = { 'rome', 'lsp-proxy' },
  filetypes = { 'javascript', 'typescript', 'json' }
})

Advanced Usage

Internal Server Command

/**
 * Run server process (internal command)
 * 
 * Usage: rome __run_server
 * 
 * Internal command used by 'rome start' to run the actual server process
 */
rome __run_server

Daemon Process Management

The daemon process:

  • Auto-discovery: Commands automatically find running daemon
  • Socket communication: Uses Unix sockets (Linux/macOS) or named pipes (Windows)
  • Process isolation: Daemon runs as separate process
  • Resource management: Automatically cleans up resources

Error Handling

# Daemon not running
rome check src/ --use-server
# Error: ServerNotRunning

# Daemon connection failed
rome check src/ --use-server
# Falls back to direct execution

# Multiple daemon instances
rome start
# Reports if daemon already running

Performance Considerations

When to Use Daemon Mode

Recommended for:

  • Development workflows: Frequent format/check cycles
  • CI/CD pipelines: Multiple Rome commands in sequence
  • Editor integration: Real-time feedback
  • Large codebases: Significant startup overhead

Not necessary for:

  • Single-shot commands: One-time formatting or checking
  • Small projects: Minimal startup overhead
  • Memory-constrained environments: Daemon uses additional memory

Memory Usage

The daemon maintains caches that use memory:

# Monitor daemon memory usage
ps aux | grep rome

# Restart daemon to clear caches if needed
rome stop
rome start

File System Watching

The daemon can watch for file changes:

  • Automatic invalidation: Clears cache for changed files
  • Smart rebuilding: Only re-processes affected files
  • Configuration changes: Automatically reloads rome.json

Troubleshooting

Common Issues

# Daemon won't start
rome start
# Check if port/socket is already in use

# Commands hang with --use-server
# Daemon may be unresponsive, restart it:
rome stop
rome start

# Stale cache issues
# Restart daemon to clear all caches:
rome stop
rome start

Debugging

# Enable verbose output
rome start --verbose

# Check socket information
rome __print_socket

# Test daemon connectivity
rome check --version --use-server

Platform-Specific Considerations

Linux/macOS

  • Uses Unix domain sockets
  • Socket files created in temp directory
  • Automatic cleanup on daemon exit

Windows

  • Uses named pipes
  • Pipe names follow Windows conventions
  • Similar cleanup behavior

Integration Patterns

Build Scripts

{
  "scripts": {
    "start-rome": "rome start",
    "stop-rome": "rome stop", 
    "dev": "rome start && npm run dev:watch && rome stop",
    "lint": "rome check src/ --use-server",
    "format": "rome format src/ --write --use-server"
  }
}

Git Hooks

#!/bin/sh
# pre-commit hook
rome start 2>/dev/null || true
rome check --staged --use-server || exit 1
rome format --staged --write --use-server || exit 1

Docker Integration

# Start daemon in container
RUN rome start

# Use daemon for build steps
RUN rome check src/ --use-server
RUN rome format src/ --use-server

# Daemon automatically stops when container exits

Install with Tessl CLI

npx tessl i tessl/npm-rome

docs

ci-integration.md

configuration.md

daemon-mode.md

formatting.md

index.md

linting.md

tile.json