#!/usr/bin/env node import * as fs from 'fs'; import * as os from 'os'; import * as path from 'path'; import { send, setDebug, setSession, getSession } from './client.js'; import type { Response } from './types.js'; /** * List all active veb sessions */ function listSessions(): string[] { const tmpDir = os.tmpdir(); try { const files = fs.readdirSync(tmpDir); const sessions: string[] = []; for (const file of files) { const match = file.match(/^veb-(.+)\.pid$/); if (match) { const pidFile = path.join(tmpDir, file); try { const pid = parseInt(fs.readFileSync(pidFile, 'utf8').trim(), 10); // Check if process is still running process.kill(pid, 0); sessions.push(match[1]); } catch { // Process not running, ignore } } } return sessions; } catch { return []; } } // ANSI colors const colors = { reset: '\x1b[0m', bold: '\x1b[1m', dim: '\x1b[2m', red: '\x1b[31m', green: '\x1b[32m', yellow: '\x1b[33m', blue: '\x1b[34m', magenta: '\x1b[35m', cyan: '\x1b[36m', }; const c = (color: keyof typeof colors, text: string) => `${colors[color]}${text}${colors.reset}`; function printHelp(): void { console.log(` ${c('bold', 'veb')} - headless browser automation for agents and humans ${c('yellow', 'Usage:')} veb [options] ${c('yellow', 'Commands:')} ${c('cyan', 'open')} Open a URL in the browser ${c('cyan', 'click')} Click an element ${c('cyan', 'dblclick')} Double-click an element ${c('cyan', 'type')} Type text into an element ${c('cyan', 'fill')} Clear and fill input ${c('cyan', 'press')} Press a keyboard key ${c('cyan', 'check')} Check a checkbox/radio ${c('cyan', 'uncheck')} Uncheck a checkbox ${c('cyan', 'select')} Select dropdown option ${c('cyan', 'hover')} Hover over an element ${c('cyan', 'focus')} Focus an element ${c('cyan', 'drag')} Drag and drop ${c('cyan', 'upload')} Upload files ${c('cyan', 'wait')} Wait for element, text, or duration ${c('cyan', 'screenshot')} [path] Take a screenshot ${c('cyan', 'pdf')} Save page as PDF ${c('cyan', 'snapshot')} Get accessibility tree (for agents) ${c('cyan', 'extract')} Extract element content ${c('cyan', 'eval')}