npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@shelltender/core

v0.7.0

Published

Shared types, interfaces, and utilities for Shelltender

Readme

@shelltender/core

Shared types, interfaces, and constants for the Shelltender web-based persistent terminal system. This package provides the foundational type definitions used across all Shelltender packages.

Installation

npm install @shelltender/core

Overview

The @shelltender/core package exports TypeScript types and constants that define the contracts between Shelltender's server and client components. It ensures type safety and consistency across the entire Shelltender ecosystem.

Usage

import { 
  TerminalSession, 
  SessionOptions, 
  TerminalData,
  MessageType,
  DEFAULT_COLS,
  DEFAULT_ROWS 
} from '@shelltender/core';

// Create a typed session configuration
const options: SessionOptions = {
  command: '/bin/bash',
  cwd: '/home/user',
  cols: DEFAULT_COLS,
  rows: DEFAULT_ROWS,
  restrictToPath: '/home/user/sandbox',
  allowUpwardNavigation: false
};

// Handle typed WebSocket messages
const message: TerminalData = {
  type: MessageType.OUTPUT,
  sessionId: 'session-123',
  data: 'Hello from terminal!'
};

API Reference

Terminal Types

TerminalSession

Represents a terminal session with its metadata and configuration.

interface TerminalSession {
  id: string;                    // Unique session identifier
  createdAt: string;            // ISO timestamp of creation
  lastAccessedAt: string;       // ISO timestamp of last access
  title?: string;               // Optional session title
  cols: number;                 // Terminal width in columns
  rows: number;                 // Terminal height in rows
  command?: string;             // Custom command (if any)
  args?: string[];              // Command arguments
  locked?: boolean;             // Whether session is locked
}

TerminalEvent

Represents events that occur within a terminal session.

interface TerminalEvent {
  type: 'bell' | 'output-match' | 'exit' | 'error';
  sessionId: string;
  timestamp: string;
  data?: any;
}

Session Types

SessionOptions

Configuration options for creating new terminal sessions.

interface SessionOptions {
  // Basic options
  command?: string;              // Shell command to run
  args?: string[];              // Command arguments
  cwd?: string;                 // Working directory
  env?: Record<string, string>; // Environment variables
  locked?: boolean;             // Lock session from changes
  cols?: number;                // Terminal columns
  rows?: number;                // Terminal rows
  
  // Filesystem restrictions
  restrictToPath?: string;      // Confine to directory
  allowUpwardNavigation?: boolean; // Allow .. navigation
  blockedCommands?: string[];   // Forbidden commands
  readOnlyMode?: boolean;       // Block write operations
}

WebSocket Types

TerminalData

WebSocket message structure for terminal communication.

interface TerminalData {
  type: string;                 // Message type (see MessageType)
  sessionId?: string;           // Target session ID
  data?: string;                // Terminal input/output data
  cols?: number;                // Resize: new column count
  rows?: number;                // Resize: new row count
  scrollback?: string;          // Session history buffer
  exitCode?: number;            // Process exit code
  options?: SessionOptions;     // Session creation options
}

Constants

MessageType

WebSocket message type constants.

const MessageType = {
  OUTPUT: 'output',          // Terminal output data
  INPUT: 'input',            // User input data
  RESIZE: 'resize',          // Terminal resize event
  CREATE: 'create',          // Create new session
  CONNECT: 'connect',        // Connect to session
  DISCONNECT: 'disconnect',  // Disconnect from session
  ERROR: 'error',            // Error message
  BELL: 'bell',             // Terminal bell
  EXIT: 'exit'              // Session exit
} as const;

Terminal Defaults

const DEFAULT_COLS = 80;           // Default terminal width
const DEFAULT_ROWS = 24;           // Default terminal height
const DEFAULT_BUFFER_SIZE = 10000; // Scrollback buffer lines
const DEFAULT_SHELL = /* platform-specific */; // Default shell command

Type Safety

All types are exported with proper TypeScript definitions, enabling:

  • Compile-time type checking
  • IDE autocomplete and IntelliSense
  • Consistent API contracts across packages
  • Easy refactoring and maintenance

Examples

Creating a Restricted Session

import { SessionOptions } from '@shelltender/core';

const sandboxOptions: SessionOptions = {
  restrictToPath: '/tmp/sandbox',
  allowUpwardNavigation: false,
  blockedCommands: ['rm', 'dd', 'mkfs'],
  readOnlyMode: false,
  env: {
    PS1: 'sandbox> '
  }
};

Handling Terminal Events

import { TerminalEvent } from '@shelltender/core';

function handleEvent(event: TerminalEvent) {
  switch (event.type) {
    case 'bell':
      console.log('Terminal bell at', event.timestamp);
      break;
    case 'exit':
      console.log('Session', event.sessionId, 'exited');
      break;
    case 'output-match':
      console.log('Pattern matched:', event.data);
      break;
  }
}

Type-Safe WebSocket Communication

import { TerminalData, MessageType } from '@shelltender/core';

// Send user input
const inputMessage: TerminalData = {
  type: MessageType.INPUT,
  sessionId: 'abc123',
  data: 'ls -la\n'
};

// Handle resize
const resizeMessage: TerminalData = {
  type: MessageType.RESIZE,
  sessionId: 'abc123',
  cols: 120,
  rows: 40
};

Related Packages

License

MIT