@dailyautomations/terminal-logger
v0.1.0
Published
Terminal command logger with Supabase sync for swarm prompts
Downloads
29
Maintainers
Readme
Terminal Logger
A Node.js/TypeScript package that captures terminal commands and syncs them to Supabase for tracking swarm prompts and command history.
Features
- 📝 Captures terminal commands from shell history
- 🔄 Syncs commands to Supabase database
- 🤖 Detects and tags swarm-related commands
- 💾 Local JSON storage with automatic backups
- ⏰ Configurable sync intervals
- 🔍 Search and query command history
- 📊 Session tracking and metadata
Installation
npm install @dailyautomations/terminal-loggerOr clone and build from source:
git clone <repo>
cd terminal-logger
npm install
npm run buildSetup
- Run the setup script:
npm run setup- Configure your
.envfile:
SUPABASE_URL=your-supabase-url
SUPABASE_ANON_KEY=your-supabase-anon-key
LOG_FILE_PATH=./logs/commands.json
SYNC_INTERVAL_MINUTES=5
ENABLE_REAL_TIME_SYNC=false- Create Supabase tables:
-- Terminal Commands Table
CREATE TABLE terminal_commands (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
command_id TEXT UNIQUE NOT NULL,
timestamp TIMESTAMPTZ NOT NULL,
command TEXT NOT NULL,
directory TEXT NOT NULL,
user_name TEXT NOT NULL,
session_id TEXT NOT NULL,
hostname TEXT NOT NULL,
exit_code INTEGER,
duration INTEGER,
metadata JSONB,
created_at TIMESTAMPTZ DEFAULT NOW()
);
-- Sessions Table
CREATE TABLE terminal_sessions (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
session_id TEXT UNIQUE NOT NULL,
start_time TIMESTAMPTZ NOT NULL,
end_time TIMESTAMPTZ,
user_name TEXT NOT NULL,
hostname TEXT NOT NULL,
shell TEXT NOT NULL,
terminal TEXT NOT NULL,
created_at TIMESTAMPTZ DEFAULT NOW()
);
-- Create indexes
CREATE INDEX idx_commands_timestamp ON terminal_commands(timestamp);
CREATE INDEX idx_commands_session ON terminal_commands(session_id);
CREATE INDEX idx_commands_metadata ON terminal_commands(metadata);Usage
As a standalone service:
npm startAs a library:
import { TerminalLogger } from '@dailyautomations/terminal-logger';
const logger = new TerminalLogger();
// Start logging
await logger.start();
// Get recent commands
const recentCommands = await logger.getRecentCommands(50);
// Search commands
const searchResults = await logger.searchCommands('claude-flow');
// Get swarm commands
const swarmCommands = await logger.getSwarmCommands();
// Check sync status
const syncStatus = logger.getSyncStatus();
// Stop logging
await logger.stop();Shell Integration
Add to your ~/.bashrc or ~/.zshrc:
# Ensure history is written immediately
export PROMPT_COMMAND='history -a'
# Or for zsh:
# setopt INC_APPEND_HISTORYConfiguration
| Environment Variable | Description | Default |
|---------------------|-------------|---------|
| SUPABASE_URL | Supabase project URL | - |
| SUPABASE_ANON_KEY | Supabase anonymous key | - |
| LOG_FILE_PATH | Local JSON log file path | ./logs/commands.json |
| SYNC_INTERVAL_MINUTES | Minutes between syncs | 5 |
| ENABLE_REAL_TIME_SYNC | Sync immediately on command | false |
| SHELL_HISTORY_FILE | Shell history file path | ~/.bash_history |
| WATCH_INTERVAL_MS | History check interval | 1000 |
| LOG_LEVEL | Logging level | info |
Swarm Command Detection
The logger automatically detects and tags swarm-related commands:
- Commands containing
claude-flow swarm - Commands with
npx claude-flow - MCP tool invocations (
mcp__*__*) - Swarm operations (init, spawn, orchestrate)
Tagged metadata includes:
isSwarmPrompt: booleanswarmId: extracted swarm identifieragentType: detected agent typetaskId: associated task ID
Development
# Install dependencies
npm install
# Build TypeScript
npm run build
# Watch mode
npm run watch
# Run tests
npm test
# Lint code
npm run lint
# Format code
npm run formatLicense
MIT
